I am trying to use order_target
to buy one share of the stock, with the capital_base=
argument (for the run_algorithm()
function) equals to the price of the first day. I expect to see the perf.portfolio_value
is the same as (at least similar to) the perf.price
, which is the variable in record
to record the stock price. Questions:
I use
start=2016-1-1
, but the first element in theperf
is2016-1-4
, which is the next date in my data. Doesstart
actually start from the next business day?Why I got slightly different results between portfolio and the stock price starting from the second day? (for the first day, I think they are equal due to I set
capital_base=
first day price).
In the result, und_price
is the underlying price that I record for the stock price. portfolio_value
is the zipline tracking for the portfolio value. Notice that they have the same value for Jan 4, which is 1.0831. Why their prices are different on Jan 5? Moreover, portfolio value (1.081563) is higher than the price(1.0748)? (I assume I did not set transaction fee, even if there is transaction fee, why the portfolio value is higher)
3. I changed capital_base=0.081
and order_target(context.asset, 1)
, where I do not have enough money to buy one share. Why the zipline.run_algorithm
can still run without any problem? Why not throwing an error saying sth like "nor enough money to buy target share"?
perf.und_price.head()
2016-01-04 21:00:00+00:00 **1.0831**
2016-01-05 21:00:00+00:00 **1.0748**
2016-01-06 21:00:00+00:00 1.0781
2016-01-07 21:00:00+00:00 1.0932
2016-01-08 21:00:00+00:00 1.0922
Name: und_price, dtype: float64
perf.portfolio_value.head()
2016-01-04 21:00:00+00:00 **1.083100**
2016-01-05 21:00:00+00:00 **1.081563**
2016-01-06 21:00:00+00:00 1.084863
2016-01-07 21:00:00+00:00 1.099963
2016-01-08 21:00:00+00:00 1.098963
Name: portfolio_value, dtype: float64
Here is my code:
def initialize(context):
context.i = 0
context.asset = symbol('EUR')
set_benchmark(context.asset)
def handle_data(context, data):
order_target(context.asset, 1)
record(und_price=data.current(context.asset, 'price'))
perf = zipline.run_algorithm(start=datetime(2016, 1, 1, 0, 0, 0, 0, pytz.utc),
end=datetime(2018, 1, 1, 0, 0, 0, 0, pytz.utc),
initialize=initialize,
capital_base=0.0831,
handle_data=handle_data,
data=dat)
Well, overall, the price behavior looks similar. I just want to know the cause of the slight difference (since I did not intend to set sth like transaction cost).