Back to Community
Issue with timestamps

EDIT: So I figured out this problem. Essentially I was getting really confused by the date issue within the transaction log. The transaction log suffers from the same problem that the debug logs used to suffer from. Essentially the trade log thinks its yesterday when its today. If the trade is listed as filled April 4 it actually filled on April 5. However, if you print a statement saying "I bought SPY on this date." the statement would print on the 4th because the order is placed on the 4th but filled on the 5th (I'm using daily data).

7 responses
Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
import datetime
import math
import numpy
import pandas

def clean_col(df):
    df = df.fillna(0)
    df = df[['Nshares', 'sid']]
    log.info(' \n %s % df.head()')
    return df

def initialize(context):
    #
    #Read universe
    context.SPY=sid(8554)
    context.Sectors=[sid(19662), sid(19659), sid(19656), sid(19661), sid(19655), sid(19658), sid(19660), sid(19654), sid(19657)]  
    
    #Read the rankings
    fetch_csv('https://dl.dropboxusercontent.com/s/229wmdunmljdqmy/Truncated_Tradelog_Tminus1.csv',
              date_column='Date',
              post_func=clean_col)

    
    

def handle_data(context, data):
    
    for i in context.Sectors:
        if 'Nshares' in data[i] and data[i]['Nshares']!=0:
            log.debug("Ordering "+str(data[i]['Nshares'])+" of ticker "+str(i))
            order(i,data[i]['Nshares'])
        #else:
            #log.debug("Nshares not found for "+str(i))

            
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.
Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
import datetime
import math
import numpy
import pandas

def clean_col(df):
    df = df.fillna(0)
    df = df[['Nshares', 'sid']]
    log.info(' \n %s % df.head()')
    return df

def initialize(context):
    #
    #Read universe
    context.SPY=sid(8554)
    context.Sectors=[sid(19662), sid(19659), sid(19656), sid(19661), sid(19655), sid(19658), sid(19660), sid(19654), sid(19657)]  
    
    #Read the rankings
    fetch_csv('https://dl.dropboxusercontent.com/s/o9l7x6ws4rvb53y/TradeLog_Trun.csv',
              date_column='Date',
              post_func=clean_col)

    
    

def handle_data(context, data):
    
    for i in context.Sectors:
        if 'Nshares' in data[i] and data[i]['Nshares']!=0:
            log.debug("Ordering "+str(data[i]['Nshares'])+" of ticker "+str(i))
            order(i,data[i]['Nshares'])
        #else:
            #log.debug("Nshares not found for "+str(i))

            
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

We've had a series of discussions about how to manage timestamps better. Not surprisingly, it's a tough problem. UTC, DST, "market time" and each Quantopian member's local timezone make for some twisted time relationship. The first goal is to make it easy for the algo writer to understand what's going on without having to think about it. The second goal is to make it easy for people to share ideas even when they are in different timezones. It's difficult to satisfy all of the goals and remain consistent. I'm hopeful that next week we'll settle on an overall strategy.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Understood. Plus consider astronauts in orbit who are trading their Scottrade accounts - you need to take into account relativistic effects, etc. (Just kidding, obviously.... nerdy joke)

Daniel,

It could be true sooner than you think.....

http://www.antonkreil.com/space/

P.

That is awesome Peter. I often think about how I could exploit arbitrage opportunities if we colonized another planet in the solar system and had exchanges on both planets. The interplanetary transmission could take 5-10 minutes.... there'd definitely be some way to manipulate that lag in information.

Really interesting subject to think about. Great article about it from Wilmott.com:

Space-Time Finance: The Relativity Theory’s Implications for Mathematical Finance