Skip to content

How to place exact dollar value to buy/sell #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adamrg73 opened this issue Jan 18, 2021 · 5 comments
Closed

How to place exact dollar value to buy/sell #226

adamrg73 opened this issue Jan 18, 2021 · 5 comments
Labels
question Not a bug, but a FAQ entry

Comments

@adamrg73
Copy link

var size
Order size (negative for short orders).

If size is a value between 0 and 1, it is interpreted as a fraction of current available liquidity (cash plus Position.pl minus used margin). A value greater than or equal to 1 indicates an absolute number of units.

I dont understand how to know how much dollars the size is if its greater than 1.

I want to be able to do for example, 1 contract of XYZ/USD = $3.91 USD

I want to be able to work with numbers like that and place orders and do position sizing with this type of contracts.
Thanks

@kernc
Copy link
Owner

kernc commented Jan 18, 2021

A value greater than or equal to 1 indicates an absolute number of units.

If one unit of asset (e.g. a contract) costs $3.91 and you want to spend $10, you just have to figure out how many (whole) units fit in to sum at most $10. Basic arithmetic. Does this help?

Please also review the existing FAQ. This sort of question had been answered a couple times already.

@adamrg73
Copy link
Author

adamrg73 commented Jan 19, 2021

Hi I checked some your reply on another post, it says:

current_price = self.data.Close[-1]
order_size = 100 // current_price

so if YFIUSD last close price = 36521
I wana buy 1 contract of that which is on the exchange, 36521 / 10000 = $3.65

so then on your backtesting.py i put:

current_price = self.data.Close[-1]
order_size = 100 // current_price

this is my actual code:
order_size = (self.data.Close[-1]/10000) // self.data.Close[-1]
print('ordersize:'+str(order_size))
self.sell(size=order_size)

I get 0. No trades execute.
?

@adamrg73

This comment has been minimized.

@kernc
Copy link
Owner

kernc commented Jan 31, 2021

order_size = 100 // current_price

from #137 indicates the number of units fitting into $100 allowance. In your case:

order_size = 100 // 3.65  # should be: 27

In that case, also make sure your input dataframe is denominated in unit prices (e.g. $3.65), not contract prices ($36,521).

Alternatively, if you just want to sell one mini lot, pass:

self.sell(size=10_000)

@kernc kernc changed the title Please explain how to place exact dollar value to buy/sell How to place exact dollar value to buy/sell Feb 13, 2021
@kernc kernc added the question Not a bug, but a FAQ entry label Feb 13, 2021
@kernc kernc closed this as completed Feb 13, 2021
@nikolhaas65
Copy link

Hi, I have rediscovered the same issue and tried to find the root of that.
Besides, the solution order_size = 100 USD // 100.000 USD (trade with 100 USD on BTC-PERPETUAL) will not work, because in this case order_size = 0.

my request
#1198

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

3 participants