quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.72k stars 1.78k forks source link

Understanding the Position dataframe example #685

Open Rajmehta123 opened 3 years ago

Rajmehta123 commented 3 years ago

Problem Description

Not any coding error but just trying to understand the position csv (test_pos.tar.gz/test_pos.csv).

The position is calculated by the present amount of assets in the portfolio by their corresponding price in transactions (test_txn.tar.gz/test_txn.csv). Then, how can the value be negative as the number of assets in a portfolio cannot be negative?

The tears.py describes the position as:

Parameters
----------
returns : pd.Series
    Daily returns of the strategy, noncumulative.
     - Time series with decimal returns.
     - Example:
        2015-07-16    -0.012143
        2015-07-17    0.045350
        2015-07-20    0.030957
        2015-07-21    0.004902
positions : pd.DataFrame, optional
    Daily net position values.
     - Time series of dollar amount invested in each position and cash.
     - Days where stocks are not held can be represented by 0 or NaN.
     - Non-working capital is labelled 'cash'
     - Example:
        index         'AAPL'         'MSFT'          cash
        2004-01-09    13939.3800     -14012.9930     711.5585
        2004-01-12    14492.6300     -14624.8700     27.1821
        2004-01-13    -13853.2800    13653.6400      -43.6375