Ejemplo n.º 1
0
def create_simulation_parameters(year=2006,
                                 start=None,
                                 end=None,
                                 capital_base=float("1.0e5"),
                                 num_days=None,
                                 emission_rate='daily',
                                 data_frequency='daily'):
    """Construct a complete environment with reasonable defaults"""
    if start is None:
        start = datetime(year, 1, 1, tzinfo=pytz.utc)
    if end is None:
        if num_days:
            trading.environment = trading.TradingEnvironment()
            start_index = trading.environment.trading_days.searchsorted(start)
            end = trading.environment.trading_days[start_index + num_days - 1]
        else:
            end = datetime(year, 12, 31, tzinfo=pytz.utc)
    sim_params = trading.SimulationParameters(
        period_start=start,
        period_end=end,
        capital_base=capital_base,
        emission_rate=emission_rate,
    )

    return sim_params
Ejemplo n.º 2
0
    def create_simulation_parameters(self,
                                     start=None,
                                     end=None,
                                     capital_base=float("1.0e5"),
                                     emission_rate=None,
                                     data_frequency=None):
        if emission_rate is None:
            emission_rate = 'minute' if str(self.period) == 1 else 'daily'

        if data_frequency is None:
            data_frequency = 'minute' if str(self.period) == 1 else 'daily'

        if start is None:
            start = datareader.timetastic(self.start, datareader.pytz.utc)

        if end is None:
            end = datareader.timetastic(self.end, datareader.pytz.utc)

        return trading.SimulationParameters(period_start=start,
                                            period_end=end,
                                            capital_base=capital_base,
                                            emission_rate=emission_rate,
                                            data_frequency=data_frequency)
Ejemplo n.º 3
0
            self.atr_plot[sym]['loss'].append(-(atr*3)+sym_price)
        self.day_count += 1

if __name__ == '__main__':
    data = load_bars_from_yahoo(stocks=sym_list, indexes={}, start=start, end=end)
    trend_trader = trend_trader()
    results = trend_trader.run(data)

    ###########################################################################
    # Generate metrics
    print 'Generating Risk Report...........'
    print 'Using S&P500 as benchmark........'

    start = results.first_valid_index().replace(tzinfo=pytz.utc)
    end = results.last_valid_index().replace(tzinfo=pytz.utc)
    env = trading.SimulationParameters(start, end)
    returns_risk = create_returns_from_list(results.returns, env)
    
    algo_returns = RiskMetricsBase(start, end, returns_risk).algorithm_period_returns
    benchmark_returns = RiskMetricsBase(start, end, returns_risk).benchmark_period_returns
    excess_return = RiskMetricsBase(start, end, returns_risk).excess_return
    algo_volatility = RiskMetricsBase(start, end, returns_risk).algorithm_volatility
    benchmark_volatility = RiskMetricsBase(start, end, returns_risk).benchmark_volatility
    sharpe = RiskMetricsBase(start, end, returns_risk).sharpe
    sortino = RiskMetricsBase(start, end, returns_risk).sortino
    information = RiskMetricsBase(start, end, returns_risk).information
    beta = RiskMetricsBase(start, end, returns_risk).beta
    alpha = RiskMetricsBase(start, end, returns_risk).alpha
    max_drawdown = RiskMetricsBase(start, end, returns_risk).max_drawdown
    
    print '---------Risk Metrics---------'