0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Some tools

Last updated at Posted at 2019-01-12

コスト関数

def trading_cost_bps(participation_ratio=0.1, commission_bps=10):
    c=commission_bps
    p=participation_ratio
    return (-1/(p/15+0.01)+200)/3.4-24+c

バックテスター

import pandas as pd
from datetime import date, datetime as dt
import random

def default_manager(d):
    """Manages each of process of back testing
    """
    print('Start back testing...')
    d.log=pd.DataFrame(0, index=d.dates, columns=d.universe)
    for date in d.dates:
        d.each_day(date)
        print(d.log)
    print('Backtest completed.')
    
    
class BackTestWorker(object):
    """Works as if a trader for each of the day
    """
    def __init__(self, universe, rule, dates, manager=default_manager, 
                 *args,**kwargs):
        self.universe=universe
        self.rule=rule
        self.dates=dates
        self.manager=manager
        self.args=args
        self.kwargs=kwargs
        
        
    def each_day(self, date):
        return self.rule(self, date)
        
    def run(self):
        self.manager(self)

def random_buyer(d, date):
    if date==d.dates[0]:
        d.log.loc[date,random.sample(d.universe,2)]=1
    else:
        pass

    
    
if __name__ == '__main__':
    BackTestWorker(
        ['3382','7203','2651'],
        random_buyer,
        [date(2007, 12, 5), date(2007, 12, 6), date(2007, 12, 7)]
    ).run()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?