Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: systematicinvestor <[email protected]>
  • Loading branch information
systematicinvestor committed Aug 24, 2017
1 parent fa25225 commit cc462c4
Show file tree
Hide file tree
Showing 69 changed files with 1,581 additions and 993 deletions.
31 changes: 16 additions & 15 deletions R/aa.bl.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Black-Litterman model Functions
# Copyright (C) 2011 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down
31 changes: 16 additions & 15 deletions R/aa.gmpl.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Read GNU MathProg model
# Copyright (C) 2012 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down
31 changes: 16 additions & 15 deletions R/aa.omega.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Optimizing Omega Ration Functions
# Copyright (C) 2011 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down
31 changes: 16 additions & 15 deletions R/aa.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Asset Allocation Functions
# Copyright (C) 2011 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down
33 changes: 17 additions & 16 deletions R/aa.test.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Test cases for Asset Allocation Functions
# Copyright (C) 2011 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down Expand Up @@ -2158,7 +2159,7 @@ aa.test.create.ia <- function()
#--------------------------------------------------------------------------
# Create historical input assumptions
#--------------------------------------------------------------------------
ia = create.historical.ia(hist.returns, 12, symbols, symbol.names)
ia = create.historical.ia(hist.returns, 12)

return(ia)
}
Expand Down
31 changes: 16 additions & 15 deletions R/branchbound.r
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Binary Branch and Bound and it's adaption for QP problem
# Copyright (C) 1998-2000 Alberto Bemporad, Domenico Mignone - author's of the original Matlab version
# Copyright (C) 2011 Michael Kapler - adapted code to R
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down
35 changes: 18 additions & 17 deletions R/bt.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Backtest Functions
# Copyright (C) 2011 Michael Kapler
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down Expand Up @@ -737,7 +738,7 @@ bt.trim <- function
bt$equity = bt$equity[index]
bt$equity = bt$equity / as.double(bt$equity[1])
bt$ret = bt$ret[index]
bt$weight = bt$weight[index,,drop=F]
if (!is.null(bt$weight)) bt$weight = bt$weight[index,,drop=F]
if (!is.null(bt$share)) bt$share = bt$share[index,,drop=F]

bt$best = max(bt$ret)
Expand Down Expand Up @@ -2038,7 +2039,7 @@ bt.simple.test <- function()
#' weight = matrix(weight, nrow=2, byrow=TRUE)
#' print(bt.apply.min.weight(weight, 0.1))
#' }
#' @author Ivan Popivanov and Michael Kapler
#' @author Ivan Popivanov
#' @export
###############################################################################
# Possible use
Expand Down
36 changes: 19 additions & 17 deletions R/bt.share.r
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
###############################################################################
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Backtest Functions
# Copyright (C) 2015 Systematic Investor
# Backtest Functions based on shares invested
#
# For more information please visit my blog at www.SystematicInvestor.wordpress.com
# or drop me a line at TheSystematicInvestor at gmail
# For more information please email at TheSystematicInvestor at gmail
###############################################################################


Expand Down Expand Up @@ -220,6 +221,7 @@ bt.run.share.ex <- function

prices = coredata(prices)
n = ncol(prices)
nperiods = nrow(prices)

# execution.price logic
trade = !is.na(weight)
Expand Down Expand Up @@ -266,7 +268,7 @@ bt.run.share.ex <- function


bankrupt = which(bt$ret <= -1)
if(len(bankrupt) > 0) bt$ret[bankrupt[1]:n] = -1
if(len(bankrupt) > 0) bt$ret[bankrupt[1]:nperiods] = -1


bt$equity = cumprod(1 + bt$ret)
Expand Down
21 changes: 21 additions & 0 deletions R/bt.share.test.r
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
###############################################################################
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
###############################################################################
# Evaluating Sample Trading Strategies using Backtesting library
#
# For more information please email at TheSystematicInvestor at gmail
###############################################################################

bt.run.share.ex.example.match.adjusted.unadjusted = function()
{
Expand Down
Loading

0 comments on commit cc462c4

Please sign in to comment.