Skip to content

Profit Loss

Profit loss

The feature of list_profit_loss is used to query profit loss of account and you need to login first.

In

api.list_profit_loss?

Out

Signature:
    api.list_profit_loss(
        account: shioaji.account.Account = None,
        begin_date: str = '',
        end_date: str = '',
        timeout: int = 5000,
        cb: Callable[[List[shioaji.position.ProfitLoss]], NoneType] = None,
    ) -> List[shioaji.position.ProfitLoss]
Docstring:
    query account of profit loss

    Args:
        account (:obj:Account): 
            choice the account from listing account (Default: stock account)
        begin_date (str): the start date of query profit loss (Default: today)
        end_date (str): the end date of query profit loss (Default: today)

In

api.list_profit_loss(api.stock_account,'2020-05-05','2020-05-30')

Out

[ProfitLoss(id=0, code='2890', seqno='14816', dseq='ID111', quantity=1, price=10.1, pnl=1234.0, pr_ratio=0.1237, cond='Cash', date='2020-05-22')]

In

profitloss = api.list_profit_loss(api.stock_account,'2020-05-05','2020-05-30')   
df = pd.DataFrame(profitloss)     
df     

Out

id code cond date pnl pr_ratio price quantity seqno dseq
0 2890 StockOrderCond.Cash 2020-05-22 1000.0 0.1237 10.1 1 14816 ID111

Attributes:

id (int): use to find detail.
code (str): contract id.
seqno (str): seqno no.
dseq (str): seqno no.
quantity (int): quantity.
price (float): price.
pnl (float): profit and loss.
pr_ratio (float): profit rate.
cond (StockOrderCond): {Cash, Netting, MarginTrading, ShortSelling}
date (str): trade date.

Profit loss detail

The feature of list_profit_loss_detail is used to query profit loss detail of account.

In

api.list_profit_loss_detail?

Out

Signature:
    api.list_profit_loss_detail(
        account: shioaji.account.Account = None,
        detail_id: int = 0,
        timeout: int = 5000,
        cb: Callable[[List[shioaji.position.ProfitLossDetail]], NoneType] = None,
    )
Docstring:
    query account of profit loss detail

    Args:
        account (:obj:Account): 
            choice the account from listing account (Default: stock account)
        detail_id (int): the id is from ProfitLoss object, ProfitLoss is from list_profit_loss

In

api.list_profit_loss_detail(api.stock_account,2)

Out

[ProfitLossDetail(date='2020-05-22', cond='Cash', code='2890', quantity=1, price=10.1, cost=9100, dseq='ID111', rep_margintrading_amt=0, rep_collateral=0, rep_margin=0, fee=20, interest=0, tax=0, shortselling_fee=0, currency='NTD')]

Out

date cond code quantity price cost dseq rep_margintrading_amt rep_collateral rep_margin fee interest tax shortselling_fee currency
2020-05-22 StockOrderCond.Cash 2890 1 10.1 9100 ID111 0 0 0 20 0 0 0 NTD

Attributes:

date (str): trade date.
cond (StockOrderCond): {Cash, Netting, MarginTrading, ShortSelling}
code (str): contract id.
quantity (int): quantity.
price (float): price.
cost (int): cost of price.
dseq (str): detail seqno no.
rep_margintrading_amt (int): repay amount of margin trading.
rep_collateral (int): repay collateral.
rep_margin (int): repay margin.
fee (int): fee.
interest (int): interest.
tax (int): trading tax.
shortselling_fee (int): fee of short selling. 
currency (str): {NTD, USD, HKD, EUR, CAD, BAS}

Profit loss summary

The feature of list_profit_loss_sum is used to query summary of profit loss for a period of time and you need to login first.

In

api.list_profit_loss_sum?

Out

Signature:
    api.list_profit_loss_sum(
        account: shioaji.account.Account = None,
        begin_date: str = '',
        end_date: str = '',
        timeout: int = 5000,
        cb: Callable[[List[Union[shioaji.position.StockProfitLossSum, shioaji.position.FutureProfitLossSum]]], NoneType] = None,
    ) -> List[Union[shioaji.position.StockProfitLossSum, shioaji.position.FutureProfitLossSum]]
Docstring:
    query summary profit loss of a period time 
    Args:
    account (:obj:Account):
        choice the account from listing account (Default: stock account)
    begin_date (str): the start date of query profit loss (Default: today)
    end_date (str): the end date of query profit loss (Default: today)

In

profitloss_sum = api.list_profit_loss_sum(api.stock_account,'2020-05-05','2020-05-30')
profitloss_sum

Out

ProfitLossSummaryTotal(status=<FetchStatus.Fetched: 'Fetched'>, profitloss_summary=[StockProfitLossSummary(code='2890', quantity=2000, entry_price=17, cover_price=10, pnl=-11585.0, currency='NTD', entry_cost=34550, cover_cost=21600, buy_cost=33112, sell_cost=21527, pr_ratio=-34.99)], total=ProfitLossTotal(quantity=2000, buy_cost=33112, sell_cost=21527, pnl=-11585.0, pr_ratio=-34.99))

In

df = pd.DataFrame(data.__dict__ for data in profitloss_sum.profitloss_summary) 
df     

Out

code quantity entry_price cover_price pnl currency entry_cost cover_cost buy_cost sell_cost pr_ratio cond
0 3481 2000 17 10 -11585 NTD 34550
21600 33112 21527 -34.99 Cash

Attributes:

code (str): contract id.
quantity (int): quantity.
entry_price (int): price of entry.
cover_price (int): price of cover.
pnl (float): profit and loss.
currency (str): currency.
entry_cost (int): cost of entry.
cover_cost (int): cost of cover.
buy_cost (int): cost of buy.
sell_cost (int): cost of sell.
pr_ratio (float): profit rate.
cond (StockOrderCond): {Cash, Netting, MarginTrading, ShortSelling}