Mustafa Kutay Yabas - EC581 - 29.10.2016

Assignment #3

We will test two trading strategies based on return runs.

  • Trend Following Strategy
    • Buy after n days of positive return
    • Sell after m days of negative return
  • Mean Reversion Strategy
    • Buy after n days of negative return
    • Sell after m days of positive return

Steps

  1. Apply two different trading algo for these strategies in quantstrat
  2. Apply these strategies to BIST100 index data
  3. For each strategy, optimize n and m using a grid search over set 1,2,...,100
  4. Compare optimized versions of these two strategies
  5. Is it better to be a trend-follower or a contrarian in BIST

In [1]:
# load libraries
library(quantstrat)
library(Quandl)


Loading required package: quantmod
Loading required package: xts
Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: TTR
Version 0.4-0 included new data defaults. See ?getSymbols.
Loading required package: blotter
Loading required package: FinancialInstrument
Loading required package: PerformanceAnalytics

Attaching package: ‘PerformanceAnalytics’

The following object is masked from ‘package:graphics’:

    legend

Loading required package: foreach

In [2]:
# define instruments
currency("USD")
stock("BIST", currency="USD", multiplier=1)

# get data
date_from = "2005-08-01"
date_to = "2016-05-25"

BIST<-Quandl("GOOG/INDEXIST_XU100", type="xts", start_date = date_from, end_date = date_to)
BIST<-na.omit(BIST)
BIST<-xts(coredata(BIST), as.POSIXct(time(BIST)))


'USD'
'BIST'

In [3]:
# define strategy component names
portfolio_name = "investiphi"

strategy_trend = "trend_following"
strategy_mean = "mean_reversion"

account_trend = "account_trend"
account_mean = "account_mean"

# remove if defined before
rm.strat(portfolio_name)

rm.strat(strategy_trend)
rm.strat(strategy_mean)

rm.strat(account_trend)
rm.strat(account_mean)

# create .blotter and .strategy environments
.blotter<-new.env()
.strategy<-new.env()

# init portfolio and accoiunt in .blotter
init_eq <- 100000 # 100k
init_date <- as.character(as.Date(date_from) - 1)

initPortf(portfolio_name, symbols="BIST", initDate=init_date, currency="USD")

initAcct(account_trend, portfolios=portfolio_name, initDate=init_date, currency="USD", initEq = init_eq)
initAcct(account_mean, portfolios=portfolio_name, initDate=init_date, currency="USD", initEq = init_eq)

initOrders(portfolio_name, initDate=init_date)


'investiphi'
'account_trend'
'account_mean'

In [4]:
# init strategies
strategy(strategy_trend, store=TRUE)
strategy(strategy_mean, store=TRUE)

In [5]:
# you can see whats inside
temp <- get("USD", envir=FinancialInstrument:::.instrument)
summary(temp)


            Length Class  Mode     
primary_id  1      -none- character
currency    1      -none- character
multiplier  1      -none- numeric  
tick_size   1      -none- numeric  
identifiers 0      -none- list     
type        1      -none- character

In [6]:
consecutive_days<-function(days_pos,days_neg, stock, posneg = TRUE) {
    #days_pos <- 4
    #days_neg <- 4

    #n_day_signals <- data.frame(positive = logical(length(time(stock))), negative = logical(length(time(stock))))
    n_day_signals <- data.frame(sigcol = logical(length(time(stock))))
    n_day_signals <- xts( n_day_signals, as.POSIXct(time(stock)) )
    n_day_signals[1,1] <- NA

    #Signal <- xts(c("Positive", "Negative"), as.POSIXct(time(BIST)))

    sign_counter <- 1
    sign_last <- -1
    for (i in 2:length(time(stock))) {

        sign_temp <- sign( as.numeric ( as.numeric( stock[i,4]) - as.numeric( stock[i-1,4]) ) )

        if (sign_temp == sign_last) {
            sign_counter <- sign_counter + 1
        } else {
            sign_counter <- 1
            sign_last <- sign_temp
        }

        if (posneg) {
            
            if (sign_counter == days_pos && sign_last == 1) {
                n_day_signals[i,1] <- TRUE
            } else {
                n_day_signals[i,1] <- NA
            }
            
        } else {

            if (sign_counter == days_neg && sign_last == -1) {
                n_day_signals[i,1] <- TRUE
            } else {
                n_day_signals[i,1] <- NA
            }
        }
    }
    
    if (posneg == TRUE) {
        return( n_day_signals$sigcol) 
    } else {
        return(n_day_signals$sigcol)
    }

}

In [7]:
add.signal(strategy_mean, name="consecutive_days",
           arguments = list(days_pos = 4, days_neg = 4, stock=BIST, posneg=TRUE),
           label="short"
          )

add.signal(strategy_mean, name="consecutive_days",
           arguments = list(days_pos = 4, days_neg = 4, stock=BIST, posneg=FALSE),
           label="long"
          )

add.signal(strategy_trend, name="consecutive_days",
           arguments = list(days_pos = 4, days_neg = 4, stock=BIST, posneg=TRUE),
           label="tlong"
          )

add.signal(strategy_trend, name="consecutive_days",
           arguments = list(days_pos = 4, days_neg = 4, stock=BIST, posneg=FALSE),
           label="tshort"
          )


'mean_reversion'
'mean_reversion'
'trend_following'
'trend_following'

In [8]:
order_qty = 1

In [9]:
# strategy_mean rules
add.rule(strategy_mean, name='ruleSignal',
         arguments=list(sigcol='sigcol.short',
                        sigval=1,
                        orderside='short',
                        ordertype='market',
                        orderqty=-order_qty,
                        TxnFees=0,
                        replace=FALSE),
         type='enter',
         label='EnterShort'
        )

add.rule(strategy_mean, name='ruleSignal',
         arguments=list(sigcol='sigcol.long',
                        sigval=1,
                        orderside='long',
                        ordertype='market',
                        orderqty='all',
                        TxnFees=0,
                        replace=TRUE),
         type='exit',
         label='Exit2Long'
        )

add.rule(strategy_mean, name='ruleSignal',
         arguments=list(sigcol='sigcol.long',
                        sigval=TRUE,
                        orderside='long',
                        ordertype='market',
                        orderqty=order_qty,
                        TxnFees=0,
                        replace=FALSE),
         type='enter',
         label='EnterLong'
        )

add.rule(strategy_mean, name='ruleSignal',
         arguments=list(sigcol='sigcol.short',
                        sigval=TRUE,
                        orderside='short',
                        ordertype='market',
                        orderqty='all',
                        TxnFees=0,
                        replace=TRUE),
         type='exit',
         label='Exit2Short'
        )


'mean_reversion'
'mean_reversion'
'mean_reversion'
'mean_reversion'

In [10]:
# strategy_trend rules
add.rule(strategy_trend, name='ruleSignal',
         arguments=list(sigcol='sigcol.tshort',
                        sigval=1,
                        orderside='short',
                        ordertype='market',
                        orderqty=-order_qty,
                        TxnFees=0,
                        replace=FALSE),
         type='enter',
         label='EnterShort'
        )

add.rule(strategy_trend, name='ruleSignal',
         arguments=list(sigcol='sigcol.tlong',
                        sigval=1,
                        orderside='long',
                        ordertype='market',
                        orderqty='all',
                        TxnFees=0,
                        replace=TRUE),
         type='exit',
         label='Exit2Long'
        )

add.rule(strategy_trend, name='ruleSignal',
         arguments=list(sigcol='sigcol.tlong',
                        sigval=TRUE,
                        orderside='long',
                        ordertype='market',
                        orderqty=order_qty,
                        TxnFees=0,
                        replace=FALSE),
         type='enter',
         label='EnterLong'
        )

add.rule(strategy_trend, name='ruleSignal',
         arguments=list(sigcol='sigcol.tshort',
                        sigval=TRUE,
                        orderside='short',
                        ordertype='market',
                        orderqty='all',
                        TxnFees=0,
                        replace=TRUE),
         type='exit',
         label='Exit2Short'
        )


'trend_following'
'trend_following'
'trend_following'
'trend_following'

In [11]:
#summary(get("mean_reversion", envir=.strategy))

In [12]:
# apply strategy

applyStrategy(strategy_mean, portfolio_name)
updatePortf(portfolio_name)
updateAcct(account_mean)
updateEndEq(account_mean)

applyStrategy(strategy_trend, portfolio_name)
updatePortf(portfolio_name)
updateAcct(account_trend)
updateEndEq(account_trend)


[1] "2005-08-11 03:00:00 BIST 1 @ 29111.84"
[1] "2005-08-24 03:00:00 BIST -1 @ 29372.23"
[1] "2005-10-31 02:00:00 BIST 1 @ 31963.99"
[1] "2005-11-08 02:00:00 BIST -1 @ 33749.43"
[1] "2005-11-18 02:00:00 BIST -1 @ 35314.31"
[1] "2005-12-05 02:00:00 BIST 1 @ 39130.73"
[1] "2005-12-05 02:00:00 BIST -1 @ 39130.73"
[1] "2005-12-27 02:00:00 BIST 1 @ 39015.86"
[1] "2005-12-27 02:00:00 BIST -1 @ 39015.86"
[1] "2006-01-06 02:00:00 BIST 1 @ 41905.41"
[1] "2006-01-06 02:00:00 BIST -1 @ 41905.41"
[1] "2006-02-21 02:00:00 BIST 1 @ 46710.93"
[1] "2006-02-21 02:00:00 BIST -1 @ 46710.93"
[1] "2006-03-08 02:00:00 BIST 1 @ 42340.43"
[1] "2006-04-14 03:00:00 BIST 1 @ 42212.03"
[1] "2006-04-24 03:00:00 BIST -1 @ 45278.39"
[1] "2006-05-04 03:00:00 BIST -1 @ 44251.44"
[1] "2006-06-09 03:00:00 BIST 1 @ 34802.58"
[1] "2006-06-20 03:00:00 BIST -1 @ 34601.4"
[1] "2006-07-03 03:00:00 BIST 1 @ 35456.47"
[1] "2006-07-03 03:00:00 BIST -1 @ 35456.47"
[1] "2006-07-14 03:00:00 BIST 1 @ 33831.69"
[1] "2006-08-03 03:00:00 BIST 1 @ 35262.86"
[1] "2006-08-17 03:00:00 BIST -1 @ 37885.28"
[1] "2006-08-23 03:00:00 BIST 1 @ 37121.81"
[1] "2006-09-05 03:00:00 BIST -1 @ 38180.02"
[1] "2006-09-12 03:00:00 BIST 1 @ 37624.54"
[1] "2006-09-26 03:00:00 BIST -1 @ 36432.37"
[1] "2006-09-26 03:00:00 BIST 1 @ 36432.37"
[1] "2006-10-13 03:00:00 BIST -1 @ 38486.09"
[1] "2006-11-21 02:00:00 BIST 1 @ 38501.1"
[1] "2007-01-09 02:00:00 BIST -1 @ 37083.09"
[1] "2007-01-09 02:00:00 BIST 1 @ 37083.09"
[1] "2007-01-26 02:00:00 BIST -1 @ 41846.38"
[1] "2007-02-01 02:00:00 BIST 1 @ 42301.96"
[1] "2007-02-09 02:00:00 BIST -1 @ 42185.46"
[1] "2007-02-09 02:00:00 BIST 1 @ 42185.46"
[1] "2007-03-12 02:00:00 BIST -1 @ 41978.34"
[1] "2007-04-09 03:00:00 BIST -1 @ 45889.23"
[1] "2007-05-02 03:00:00 BIST 1 @ 44256.13"
[1] "2007-05-22 03:00:00 BIST -1 @ 46369.23"
[1] "2007-06-19 03:00:00 BIST 1 @ 46231.77"
[1] "2007-06-19 03:00:00 BIST -1 @ 46231.77"
[1] "2007-07-04 03:00:00 BIST 1 @ 49476.29"
[1] "2007-07-04 03:00:00 BIST -1 @ 49476.29"
[1] "2007-07-30 03:00:00 BIST 1 @ 51459.22"
[1] "2007-11-01 02:00:00 BIST -1 @ 57371.31"
[1] "2007-12-11 02:00:00 BIST 1 @ 56271.27"
[1] "2007-12-11 02:00:00 BIST -1 @ 56271.27"
[1] "2008-01-07 02:00:00 BIST 1 @ 52569.54"
[1] "2008-01-15 02:00:00 BIST 1 @ 50377.34"
[1] "2008-03-05 02:00:00 BIST -1 @ 43468.03"
[1] "2008-03-05 02:00:00 BIST 1 @ 43468.03"
[1] "2008-03-31 03:00:00 BIST -1 @ 39015.44"
[1] "2008-03-31 03:00:00 BIST 1 @ 39015.44"
[1] "2008-04-16 03:00:00 BIST -1 @ 41555.97"
[1] "2008-04-16 03:00:00 BIST 1 @ 41555.97"
[1] "2008-05-23 03:00:00 BIST -1 @ 39960.99"
[1] "2008-05-23 03:00:00 BIST 1 @ 39960.99"
[1] "2008-06-12 03:00:00 BIST -1 @ 38593.64"
[1] "2008-06-12 03:00:00 BIST 1 @ 38593.64"
[1] "2008-06-24 03:00:00 BIST -1 @ 37275.87"
[1] "2008-06-24 03:00:00 BIST 1 @ 37275.87"
[1] "2008-07-02 03:00:00 BIST -1 @ 33566.4"
[1] "2008-07-02 03:00:00 BIST 1 @ 33566.4"
[1] "2008-07-08 03:00:00 BIST -1 @ 34894.68"
[1] "2008-07-22 03:00:00 BIST -1 @ 37616.17"
[1] "2008-08-01 03:00:00 BIST 1 @ 42984.66"
[1] "2008-08-01 03:00:00 BIST -1 @ 42984.66"
[1] "2008-08-11 03:00:00 BIST 1 @ 41733.27"
[1] "2008-08-22 03:00:00 BIST 1 @ 40894.27"
[1] "2008-09-15 03:00:00 BIST -1 @ 35081.44"
[1] "2008-09-15 03:00:00 BIST 1 @ 35081.44"
[1] "2008-10-08 03:00:00 BIST -1 @ 30772.63"
[1] "2008-10-08 03:00:00 BIST 1 @ 30772.63"
[1] "2008-10-27 02:00:00 BIST -1 @ 24336.73"
[1] "2008-10-27 02:00:00 BIST 1 @ 24336.73"
[1] "2008-11-03 02:00:00 BIST -1 @ 27987.65"
[1] "2008-11-21 02:00:00 BIST 1 @ 21965.96"
[1] "2008-12-18 02:00:00 BIST -1 @ 26395.5"
[1] "2009-01-07 02:00:00 BIST -1 @ 27892.65"
[1] "2009-02-27 02:00:00 BIST 1 @ 24026.59"
[1] "2009-02-27 02:00:00 BIST -1 @ 24026.59"
[1] "2009-03-24 02:00:00 BIST 1 @ 25001.59"
[1] "2009-03-24 02:00:00 BIST -1 @ 25001.59"
[1] "2009-05-21 03:00:00 BIST 1 @ 34720.55"
[1] "2009-05-21 03:00:00 BIST -1 @ 34720.55"
[1] "2009-06-15 03:00:00 BIST 1 @ 34690.77"
[1] "2009-06-15 03:00:00 BIST -1 @ 34690.77"
[1] "2009-06-30 03:00:00 BIST 1 @ 36949.2"
[1] "2009-06-30 03:00:00 BIST -1 @ 36949.2"
[1] "2009-07-28 03:00:00 BIST 1 @ 40001.65"
[1] "2009-07-28 03:00:00 BIST -1 @ 40001.65"
[1] "2009-08-25 03:00:00 BIST 1 @ 48073.35"
[1] "2009-08-25 03:00:00 BIST -1 @ 48073.35"
[1] "2009-09-24 03:00:00 BIST 1 @ 47980.31"
[1] "2009-09-24 03:00:00 BIST -1 @ 47980.31"
[1] "2009-11-02 02:00:00 BIST 1 @ 47456.11"
[1] "2009-11-23 02:00:00 BIST 1 @ 45801.42"
[1] "2009-12-07 02:00:00 BIST -1 @ 49915.76"
[1] "2010-01-07 02:00:00 BIST -1 @ 54972.94"
[1] "2010-02-08 02:00:00 BIST 1 @ 49933.38"
[1] "2010-02-26 02:00:00 BIST 1 @ 49705.49"
[1] "2010-03-04 02:00:00 BIST -1 @ 51440.71"
[1] "2010-03-15 02:00:00 BIST 1 @ 51971.37"
[1] "2010-03-26 02:00:00 BIST -1 @ 56610.66"
[1] "2010-05-07 03:00:00 BIST 1 @ 52686.97"
[1] "2010-06-15 03:00:00 BIST -1 @ 56421.32"
[1] "2010-07-08 03:00:00 BIST -1 @ 57345.59"
[1] "2010-07-22 03:00:00 BIST 1 @ 59919.48"
[1] "2010-07-22 03:00:00 BIST -1 @ 59919.48"
[1] "2010-07-30 03:00:00 BIST 1 @ 59866.75"
[1] "2010-07-30 03:00:00 BIST -1 @ 59866.75"
[1] "2010-08-18 03:00:00 BIST 1 @ 59443.43"
[1] "2010-08-18 03:00:00 BIST -1 @ 59443.43"
[1] "2010-09-02 03:00:00 BIST 1 @ 60865.73"
[1] "2010-09-02 03:00:00 BIST -1 @ 60865.73"
[1] "2010-09-17 03:00:00 BIST 1 @ 63862.03"
[1] "2010-09-17 03:00:00 BIST -1 @ 63862.03"
[1] "2010-10-14 03:00:00 BIST 1 @ 69225.72"
[1] "2010-10-14 03:00:00 BIST -1 @ 69225.72"
[1] "2010-12-21 02:00:00 BIST 1 @ 64819.64"
[1] "2010-12-27 02:00:00 BIST -1 @ 66356.58"
[1] "2011-01-07 02:00:00 BIST 1 @ 68770.29"
[1] "2011-01-07 02:00:00 BIST -1 @ 68770.29"
[1] "2011-02-21 02:00:00 BIST 1 @ 65129"
[1] "2011-02-21 02:00:00 BIST -1 @ 65129"
[1] "2011-02-25 02:00:00 BIST 1 @ 61367.34"
[1] "2011-03-14 02:00:00 BIST -1 @ 64530.05"
[1] "2011-03-23 02:00:00 BIST 1 @ 63719.64"
[1] "2011-03-23 02:00:00 BIST -1 @ 63719.64"
[1] "2011-04-07 03:00:00 BIST 1 @ 69490.47"
[1] "2011-04-07 03:00:00 BIST -1 @ 69490.47"
[1] "2011-04-25 03:00:00 BIST 1 @ 68870.67"
[1] "2011-04-25 03:00:00 BIST -1 @ 68870.67"
[1] "2011-05-04 03:00:00 BIST 1 @ 69437.55"
[1] "2011-05-04 03:00:00 BIST -1 @ 69437.55"
[1] "2011-05-10 03:00:00 BIST 1 @ 67259.99"
[1] "2011-05-24 03:00:00 BIST 1 @ 64561.4"
[1] "2011-07-20 03:00:00 BIST -1 @ 61636.83"
[1] "2011-07-20 03:00:00 BIST 1 @ 61636.83"
[1] "2011-08-04 03:00:00 BIST -1 @ 59325.99"
[1] "2011-08-04 03:00:00 BIST 1 @ 59325.99"
[1] "2011-08-17 03:00:00 BIST -1 @ 54217.83"
[1] "2011-09-21 03:00:00 BIST -1 @ 60827.89"
[1] "2011-09-30 03:00:00 BIST 1 @ 59693.43"
[1] "2011-09-30 03:00:00 BIST -1 @ 59693.43"
[1] "2011-10-13 03:00:00 BIST 1 @ 58543.37"
[1] "2011-10-13 03:00:00 BIST -1 @ 58543.37"
[1] "2011-11-23 02:00:00 BIST 1 @ 51091.51"
[1] "2012-01-10 02:00:00 BIST 1 @ 50781.84"
[1] "2012-01-20 02:00:00 BIST -1 @ 54888.55"
[1] "2012-01-31 02:00:00 BIST -1 @ 57171.34"
[1] "2012-02-07 02:00:00 BIST 1 @ 60545.87"
[1] "2012-02-07 02:00:00 BIST -1 @ 60545.87"
[1] "2012-02-21 02:00:00 BIST 1 @ 61252.83"
[1] "2012-02-21 02:00:00 BIST -1 @ 61252.83"
[1] "2012-03-05 02:00:00 BIST 1 @ 59685.48"
[1] "2012-03-05 02:00:00 BIST -1 @ 59685.48"
[1] "2012-03-19 02:00:00 BIST 1 @ 62537.33"
[1] "2012-03-19 02:00:00 BIST -1 @ 62537.33"
[1] "2012-03-26 03:00:00 BIST 1 @ 62561.47"
[1] "2012-04-10 03:00:00 BIST 1 @ 59987.73"
[1] "2012-05-10 03:00:00 BIST -1 @ 58820.76"
[1] "2012-05-10 03:00:00 BIST 1 @ 58820.76"
[1] "2012-06-07 03:00:00 BIST -1 @ 56695.71"
[1] "2012-06-25 03:00:00 BIST -1 @ 59479.36"
[1] "2012-07-23 03:00:00 BIST 1 @ 60736.81"
[1] "2012-07-30 03:00:00 BIST -1 @ 65032.05"
[1] "2012-08-23 03:00:00 BIST 1 @ 66079.48"
[1] "2012-08-23 03:00:00 BIST -1 @ 66079.48"
[1] "2012-09-03 03:00:00 BIST 1 @ 67208.22"
[1] "2012-09-03 03:00:00 BIST -1 @ 67208.22"
[1] "2012-09-11 03:00:00 BIST 1 @ 68105.07"
[1] "2012-09-11 03:00:00 BIST -1 @ 68105.07"
[1] "2012-09-21 03:00:00 BIST 1 @ 67891.46"
[1] "2012-10-10 03:00:00 BIST -1 @ 68457.58"
[1] "2012-12-05 02:00:00 BIST 1 @ 76038.35"
[1] "2012-12-05 02:00:00 BIST -1 @ 76038.35"
[1] "2012-12-13 02:00:00 BIST 1 @ 76963.34"
[1] "2012-12-13 02:00:00 BIST -1 @ 76963.34"
[1] "2012-12-28 02:00:00 BIST 1 @ 78579.08"
[1] "2012-12-28 02:00:00 BIST -1 @ 78579.08"
[1] "2013-01-17 02:00:00 BIST 1 @ 84860.26"
[1] "2013-01-17 02:00:00 BIST -1 @ 84860.26"
[1] "2013-03-01 02:00:00 BIST 1 @ 79867.54"
[1] "2013-03-01 02:00:00 BIST -1 @ 79867.54"
[1] "2013-03-27 02:00:00 BIST 1 @ 84195.16"
[1] "2013-03-27 02:00:00 BIST -1 @ 84195.16"
[1] "2013-04-08 03:00:00 BIST 1 @ 83346.51"
[1] "2013-04-26 03:00:00 BIST -1 @ 85112.29"
[1] "2013-05-29 03:00:00 BIST 1 @ 87174.54"
'investiphi'
'account_mean'
'account_mean'
[1] "2005-08-11 03:00:00 BIST -1 @ 29111.84"
[1] "2005-08-24 03:00:00 BIST 1 @ 29372.23"
[1] "2005-10-31 02:00:00 BIST -1 @ 31963.99"
[1] "2005-11-08 02:00:00 BIST 1 @ 33749.43"
[1] "2005-11-18 02:00:00 BIST 1 @ 35314.31"
[1] "2005-12-05 02:00:00 BIST 1 @ 39130.73"
[1] "2005-12-27 02:00:00 BIST 1 @ 39015.86"
[1] "2006-01-06 02:00:00 BIST 1 @ 41905.41"
[1] "2006-02-21 02:00:00 BIST 1 @ 46710.93"
[1] "2006-03-08 02:00:00 BIST -1 @ 42340.43"
[1] "2006-04-14 03:00:00 BIST -1 @ 42212.03"
[1] "2006-04-24 03:00:00 BIST 1 @ 45278.39"
[1] "2006-05-04 03:00:00 BIST 1 @ 44251.44"
[1] "2006-06-09 03:00:00 BIST -1 @ 34802.58"
[1] "2006-06-20 03:00:00 BIST 1 @ 34601.4"
[1] "2006-07-03 03:00:00 BIST 1 @ 35456.47"
[1] "2006-07-14 03:00:00 BIST -1 @ 33831.69"
[1] "2006-08-03 03:00:00 BIST -1 @ 35262.86"
[1] "2006-08-17 03:00:00 BIST 1 @ 37885.28"
[1] "2006-08-23 03:00:00 BIST -1 @ 37121.81"
[1] "2006-09-05 03:00:00 BIST 1 @ 38180.02"
[1] "2006-09-12 03:00:00 BIST -1 @ 37624.54"
[1] "2006-09-26 03:00:00 BIST -1 @ 36432.37"
[1] "2006-10-13 03:00:00 BIST 1 @ 38486.09"
[1] "2006-11-21 02:00:00 BIST -1 @ 38501.1"
[1] "2007-01-09 02:00:00 BIST -1 @ 37083.09"
[1] "2007-01-26 02:00:00 BIST 1 @ 41846.38"
[1] "2007-02-01 02:00:00 BIST -1 @ 42301.96"
[1] "2007-02-09 02:00:00 BIST -1 @ 42185.46"
[1] "2007-03-12 02:00:00 BIST 1 @ 41978.34"
[1] "2007-04-09 03:00:00 BIST 1 @ 45889.23"
[1] "2007-05-02 03:00:00 BIST -1 @ 44256.13"
[1] "2007-05-22 03:00:00 BIST 1 @ 46369.23"
[1] "2007-06-19 03:00:00 BIST 1 @ 46231.77"
[1] "2007-07-04 03:00:00 BIST 1 @ 49476.29"
[1] "2007-07-30 03:00:00 BIST -1 @ 51459.22"
[1] "2007-11-01 02:00:00 BIST 1 @ 57371.31"
[1] "2007-12-11 02:00:00 BIST 1 @ 56271.27"
[1] "2008-01-07 02:00:00 BIST -1 @ 52569.54"
[1] "2008-01-15 02:00:00 BIST -1 @ 50377.34"
[1] "2008-03-05 02:00:00 BIST -1 @ 43468.03"
[1] "2008-03-31 03:00:00 BIST -1 @ 39015.44"
[1] "2008-04-16 03:00:00 BIST -1 @ 41555.97"
[1] "2008-05-23 03:00:00 BIST -1 @ 39960.99"
[1] "2008-06-12 03:00:00 BIST -1 @ 38593.64"
[1] "2008-06-24 03:00:00 BIST -1 @ 37275.87"
[1] "2008-07-02 03:00:00 BIST -1 @ 33566.4"
[1] "2008-07-08 03:00:00 BIST 1 @ 34894.68"
[1] "2008-07-22 03:00:00 BIST 1 @ 37616.17"
[1] "2008-08-01 03:00:00 BIST 1 @ 42984.66"
[1] "2008-08-11 03:00:00 BIST -1 @ 41733.27"
[1] "2008-08-22 03:00:00 BIST -1 @ 40894.27"
[1] "2008-09-15 03:00:00 BIST -1 @ 35081.44"
[1] "2008-10-08 03:00:00 BIST -1 @ 30772.63"
[1] "2008-10-27 02:00:00 BIST -1 @ 24336.73"
[1] "2008-11-03 02:00:00 BIST 1 @ 27987.65"
[1] "2008-11-21 02:00:00 BIST -1 @ 21965.96"
[1] "2008-12-18 02:00:00 BIST 1 @ 26395.5"
[1] "2009-01-07 02:00:00 BIST 1 @ 27892.65"
[1] "2009-02-27 02:00:00 BIST 1 @ 24026.59"
[1] "2009-03-24 02:00:00 BIST 1 @ 25001.59"
[1] "2009-05-21 03:00:00 BIST 1 @ 34720.55"
[1] "2009-06-15 03:00:00 BIST 1 @ 34690.77"
[1] "2009-06-30 03:00:00 BIST 1 @ 36949.2"
[1] "2009-07-28 03:00:00 BIST 1 @ 40001.65"
[1] "2009-08-25 03:00:00 BIST 1 @ 48073.35"
[1] "2009-09-24 03:00:00 BIST 1 @ 47980.31"
[1] "2009-11-02 02:00:00 BIST -1 @ 47456.11"
[1] "2009-11-23 02:00:00 BIST -1 @ 45801.42"
[1] "2009-12-07 02:00:00 BIST 1 @ 49915.76"
[1] "2010-01-07 02:00:00 BIST 1 @ 54972.94"
[1] "2010-02-08 02:00:00 BIST -1 @ 49933.38"
[1] "2010-02-26 02:00:00 BIST -1 @ 49705.49"
[1] "2010-03-04 02:00:00 BIST 1 @ 51440.71"
[1] "2010-03-15 02:00:00 BIST -1 @ 51971.37"
[1] "2010-03-26 02:00:00 BIST 1 @ 56610.66"
[1] "2010-05-07 03:00:00 BIST -1 @ 52686.97"
[1] "2010-06-15 03:00:00 BIST 1 @ 56421.32"
[1] "2010-07-08 03:00:00 BIST 1 @ 57345.59"
[1] "2010-07-22 03:00:00 BIST 1 @ 59919.48"
[1] "2010-07-30 03:00:00 BIST 1 @ 59866.75"
[1] "2010-08-18 03:00:00 BIST 1 @ 59443.43"
[1] "2010-09-02 03:00:00 BIST 1 @ 60865.73"
[1] "2010-09-17 03:00:00 BIST 1 @ 63862.03"
[1] "2010-10-14 03:00:00 BIST 1 @ 69225.72"
[1] "2010-12-21 02:00:00 BIST -1 @ 64819.64"
[1] "2010-12-27 02:00:00 BIST 1 @ 66356.58"
[1] "2011-01-07 02:00:00 BIST 1 @ 68770.29"
[1] "2011-02-21 02:00:00 BIST 1 @ 65129"
[1] "2011-02-25 02:00:00 BIST -1 @ 61367.34"
[1] "2011-03-14 02:00:00 BIST 1 @ 64530.05"
[1] "2011-03-23 02:00:00 BIST 1 @ 63719.64"
[1] "2011-04-07 03:00:00 BIST 1 @ 69490.47"
[1] "2011-04-25 03:00:00 BIST 1 @ 68870.67"
[1] "2011-05-04 03:00:00 BIST 1 @ 69437.55"
[1] "2011-05-10 03:00:00 BIST -1 @ 67259.99"
[1] "2011-05-24 03:00:00 BIST -1 @ 64561.4"
[1] "2011-07-20 03:00:00 BIST -1 @ 61636.83"
[1] "2011-08-04 03:00:00 BIST -1 @ 59325.99"
[1] "2011-08-17 03:00:00 BIST 1 @ 54217.83"
[1] "2011-09-21 03:00:00 BIST 1 @ 60827.89"
[1] "2011-09-30 03:00:00 BIST 1 @ 59693.43"
[1] "2011-10-13 03:00:00 BIST 1 @ 58543.37"
[1] "2011-11-23 02:00:00 BIST -1 @ 51091.51"
[1] "2012-01-10 02:00:00 BIST -1 @ 50781.84"
[1] "2012-01-20 02:00:00 BIST 1 @ 54888.55"
[1] "2012-01-31 02:00:00 BIST 1 @ 57171.34"
[1] "2012-02-07 02:00:00 BIST 1 @ 60545.87"
[1] "2012-02-21 02:00:00 BIST 1 @ 61252.83"
[1] "2012-03-05 02:00:00 BIST 1 @ 59685.48"
[1] "2012-03-19 02:00:00 BIST 1 @ 62537.33"
[1] "2012-03-26 03:00:00 BIST -1 @ 62561.47"
[1] "2012-04-10 03:00:00 BIST -1 @ 59987.73"
[1] "2012-05-10 03:00:00 BIST -1 @ 58820.76"
[1] "2012-06-07 03:00:00 BIST 1 @ 56695.71"
[1] "2012-06-25 03:00:00 BIST 1 @ 59479.36"
[1] "2012-07-23 03:00:00 BIST -1 @ 60736.81"
[1] "2012-07-30 03:00:00 BIST 1 @ 65032.05"
[1] "2012-08-23 03:00:00 BIST 1 @ 66079.48"
[1] "2012-09-03 03:00:00 BIST 1 @ 67208.22"
[1] "2012-09-11 03:00:00 BIST 1 @ 68105.07"
[1] "2012-09-21 03:00:00 BIST -1 @ 67891.46"
[1] "2012-10-10 03:00:00 BIST 1 @ 68457.58"
[1] "2012-12-05 02:00:00 BIST 1 @ 76038.35"
[1] "2012-12-13 02:00:00 BIST 1 @ 76963.34"
[1] "2012-12-28 02:00:00 BIST 1 @ 78579.08"
[1] "2013-01-17 02:00:00 BIST 1 @ 84860.26"
[1] "2013-03-01 02:00:00 BIST 1 @ 79867.54"
[1] "2013-03-27 02:00:00 BIST 1 @ 84195.16"
[1] "2013-04-08 03:00:00 BIST -1 @ 83346.51"
[1] "2013-04-26 03:00:00 BIST 1 @ 85112.29"
[1] "2013-05-29 03:00:00 BIST -1 @ 87174.54"
'investiphi'
'account_trend'
'account_trend'

In [13]:
getEndEq(account_mean, date_to)


57370.4

In [14]:
getEndEq(account_trend, date_to)


-1822911.83

In [15]:
chart.Posn(portfolio_name, "BIST")