Back

How can I set timezone in QuantConnect Notebook

Hi all,

I am getting different date offset for ETF and Oanda CFD daily data.

How can I set timezone in a QN?

Something like:

SetTimeZone(DateTimeZone.Utc)

Does not work.

Thanks for your help

Update Backtest







0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Consider the following Quantbook:

 

%matplotlib inline
# Imports
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Jupyter")
AddReference("QuantConnect.Indicators")
from System import *
from QuantConnect import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Market import TradeBar, QuoteBar
from QuantConnect.Jupyter import *
from QuantConnect.Indicators import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import pandas as pd

# Create an instance
qb = QuantBook()

# Select asset data
assets = ["AU200AUD", "UK100GBP", "SPX500USD"]

au = qb.AddCfd("AU200AUD", Resolution.Daily, Market.Oanda)
uk = qb.AddCfd("UK100GBP", Resolution.Daily, Market.Oanda)
ny = qb.AddCfd("SPX500USD", Resolution.Daily, Market.Oanda)

# Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution
h1 = qb.History(qb.Securities.Keys, 10, Resolution.Daily)

# Plot closing prices from "SPY"
for s in assets:
h1.loc[s]["close"].plot()

 

I am now getting the following:

 


askclose askhigh asklow askopen bidclose bidhigh bidlow bidopen close high low open
symbol time
UK100GBP 2019-08-16 01:00:00 7092.8 7167.6 7036.4 7111.8 7089.5 7166.4 7035.3 7109.5 7091.15 7167.00 7035.85 7110.65
2019-08-17 01:00:00 7141.0 7146.2 7093.0 7097.8 7139.2 7144.0 7089.0 7095.5 7140.10 7145.10 7091.00 7096.65
2019-08-20 01:00:00 7192.5 7227.4 7155.8 7156.8 7190.7 7226.3 7153.7 7154.5 7191.60 7226.85 7154.75 7155.65
2019-08-21 01:00:00 7119.0 7243.4 7115.7 7186.5 7115.7 7242.3 7113.6 7182.7 7117.35 7242.85 7114.65 7184.60
2019-08-22 01:00:00 7207.8 7227.4 7103.4 7103.6 7205.5 7226.3 7099.7 7100.8 7206.65 7226.85 7101.55 7102.20
2019-08-23 01:00:00 7146.2 7222.4 7116.3 7221.8 7144.4 7220.2 7115.0 7218.0 7145.30 7221.30 7115.65 7219.90
2019-08-24 01:00:00 7038.7 7201.6 7035.5 7137.3 7036.4 7200.4 7033.0 7134.0 7037.55 7201.00 7034.25 7135.65
2019-08-28 01:00:00 7076.3 7117.4 7050.8 7096.0 7074.0 7116.1 7049.6 7094.2 7075.15 7116.75 7050.20 7095.10
2019-08-29 01:00:00 7116.3 7139.0 7053.8 7082.8 7114.5 7137.3 7052.6 7079.5 7115.40 7138.15 7053.20 7081.15
2019-08-30 01:00:00 7192.7 7206.9 7093.0 7116.3 7190.4 7205.8 7090.0 7112.5 7191.55 7206.35 7091.50 7114.40
2019-08-31 01:00:00 7234.3 7244.9 7185.8 7193.8 7232.0 7243.8 7184.4 7192.0 7233.15 7244.35 7185.10 7192.90
SPX500USD 2019-08-20 19:00:00 2897.4 2930.6 2891.9 2916.8 2896.9 2930.1 2891.3 2916.3 2897.15 2930.35 2891.60 2916.55
2019-08-21 19:00:00 2933.4 2937.4 2897.4 2897.6 2932.9 2936.9 2896.9 2896.9 2933.15 2937.15 2897.15 2897.25
2019-08-22 19:00:00 2920.7 2938.2 2902.9 2933.6 2920.2 2937.7 2902.4 2932.9 2920.45 2937.95 2902.65 2933.25
2019-08-23 19:00:00 2850.0 2935.2 2832.8 2920.8 2849.3 2934.7 2832.2 2920.1 2849.65 2934.95 2832.50 2920.45
2019-08-25 19:00:00 2823.0 2826.9 2808.9 2826.8 2822.5 2826.3 2808.2 2826.3 2822.75 2826.60 2808.55 2826.55
2019-08-26 19:00:00 2875.1 2887.0 2820.3 2823.2 2874.6 2886.5 2819.6 2822.5 2874.85 2886.75 2819.95 2822.85
2019-08-27 19:00:00 2872.8 2898.3 2859.2 2875.1 2872.3 2897.6 2858.7 2874.4 2872.55 2897.95 2858.95 2874.75
2019-08-28 19:00:00 2883.5 2889.3 2850.7 2873.0 2883.0 2888.7 2850.2 2872.3 2883.25 2889.00 2850.45 2872.65
2019-08-29 19:00:00 2922.4 2929.5 2874.2 2883.5 2921.9 2929.0 2873.7 2882.8 2922.15 2929.25 2873.95 2883.15
2019-08-30 19:00:00 2922.4 2945.5 2912.1 2922.6 2921.9 2945.0 2911.6 2921.9 2922.15 2945.25 2911.85 2922.25
2019-09-01 19:00:00 2908.0 2908.9 2894.4 2894.8 2907.5 2908.3 2892.3 2892.3 2907.75 2908.60 2893.35 2893.55
AU200AUD 2019-08-21 10:00:00 6492.0 6541.8 6467.0 6475.7 6491.0 6540.7 6465.7 6473.7 6491.50 6541.25 6466.35 6474.70
2019-08-22 10:00:00 6518.0 6521.3 6457.3 6492.7 6517.0 6520.0 6455.8 6490.7 6517.50 6520.65 6456.55 6491.70
2019-08-23 10:00:00 6488.0 6521.3 6467.1 6518.3 6487.0 6520.0 6463.6 6516.3 6487.50 6520.65 6465.35 6517.30
2019-08-24 10:00:00 6516.0 6522.3 6481.5 6488.3 6515.0 6521.0 6480.2 6486.3 6515.50 6521.65 6480.85 6487.30
2019-08-26 10:00:00 6405.0 6411.3 6393.5 6401.2 6403.0 6410.0 6392.2 6400.2 6404.00 6410.65 6392.85 6400.70
2019-08-27 10:00:00 6436.9 6472.1 6399.5 6404.7 6434.9 6468.9 6398.2 6403.7 6435.90 6470.50 6398.85 6404.20
2019-08-28 10:00:00 6453.9 6480.3 6423.4 6436.6 6451.9 6476.8 6421.7 6435.6 6452.90 6478.55 6422.55 6436.10
2019-08-29 10:00:00 6499.3 6500.6 6446.4 6454.6 6497.3 6498.3 6442.9 6451.6 6498.30 6499.45 6444.65 6453.10
2019-08-30 10:00:00 6547.8 6555.8 6459.8 6498.6 6545.8 6554.1 6458.5 6497.6 6546.80 6554.95 6459.15 6498.10
2019-08-31 10:00:00 6584.4 6599.7 6533.9 6547.5 6583.4 6598.4 6532.6 6546.5 6583.90 6599.05 6533.25 6547.00
2019-09-02 10:00:00 6562.0 6566.3 6556.0 6562.8 6561.0 6565.0 6554.7 6560.8 6561.50 6565.65 6555.35 6561.80

September second is missing for UK100 and why do we have August 31st for AU200AUD that is saturday?

 

0

Hi Islander,

You can set timezone using `qb.SetTimeZone()` in Research environment. Please also check out this documentation page for timezone settings of CFD assets.

0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed