Share and Money Management 0.18devel
|
Class to handle watch list entries. More...
Public Member Functions | |
def | __str__ (self) |
Returns the content of this instance as string. More... | |
def | getShareCount (self) |
Returns the numbers of shares in this position. More... | |
def | getVolume (self) |
Calculate the volume of a Position. More... | |
def | getPerf (self, withFee=False) |
Calculates the performance of a Position. More... | |
def | getAvgBuy (self) |
Calculates the average buy price. More... | |
def | getLastQuote (self) |
Returns the latest quotation of a share. More... | |
def | Close (self) |
Close position. More... | |
def | Open (self) |
Re-open position. More... | |
def | removeTransaction (self, transaction, deleteRelated=True) |
Delete a transaction related to this position. More... | |
Public Member Functions inherited from smm.objects.SMMBaseObject | |
def | __init__ (self, **kwargs) |
Initialise the instance and set attributes optionally. More... | |
def | __repr__ (self) |
Returns the representation of this object as string. More... | |
def | update (self, **kwargs) |
Update instance arguments. More... | |
def | add2db (self) |
Add an object to the database. More... | |
Static Public Member Functions | |
def | get (id=None, open=None, share=None, currency=None) |
Query Position objects. More... | |
def | getCount (closed=False, open=False) |
Returns the number of known Positions. More... | |
def | getInPeriod (start, end, open=False) |
Returns all Position with Transaction between start and end date. More... | |
def | getTotalVolume (currency) |
Calculate the volume of all open positions. More... | |
Static Public Attributes | |
dictionary | arguments |
string | psTopic = "smm.position" |
id = Int(default=AutoReload, primary=True) | |
Unique ID for each object. More... | |
currency_id = Int() | |
ID of the referred Currency object. More... | |
currency = Reference(currency_id, Currency.id) | |
Reference to the Currency object More... | |
notes = Unicode() | |
Additional notes to this position. More... | |
open = Bool(default=True) | |
Flag to mark open positions. More... | |
share_id = Int() | |
Property to store the ID of the referred Share object. More... | |
share = Reference(share_id, Share.id) | |
Reference to the Share object More... | |
stop_id = Int() | |
Property to store the ID of the referred Stop object. More... | |
transactions = ReferenceSet(id, Transaction.position_id) | |
Reference to all Transaction associated to this position More... | |
Static Public Attributes inherited from smm.objects.SMMBaseObject | |
dictionary | arguments |
Set of argument names for keyword arguments. More... | |
encoding = sys.stdout.encoding or sys.getdefaultencoding() | |
Encoding of all character strings. More... | |
psTopic = None | |
Publish Subscribe Topic for this class. More... | |
id = None | |
Unique ID for each object. More... | |
Static Private Attributes | |
string | __storm_table__ = "t_position" |
Use given table to store all of this class inside. More... | |
High level transactions | |
Use this high level transactions for all trans with this position. | |
def | buy (self, count, value, fee=None, exchange=None, date=datetime.date.today()) |
Buy shares for the current Position. More... | |
def | sell (self, count, value, fee=None, exchange=None, date=datetime.date.today(), autoclose=True) |
Sell parts of the current Position. More... | |
def | worthless (self, fee=None, exchange=None, date=datetime.date.today(), autoclose=True) |
Whole position expired worthless. More... | |
def | dividend (self, count, value, date=datetime.date.today()) |
Add a dividend Transaction. More... | |
def | split (self, oratio, nratio, date=datetime.date.today()) |
Do a share split. More... | |
def | swap (self, oratio, nratio, ovalue, nvalue, nshare, date=datetime.date.today(), autoclose=True) |
Do a stock swap. More... | |
Class to handle watch list entries.
def smm.objects.Position.__str__ | ( | self | ) |
Returns the content of this instance as string.
References gui.dialogs.DlgTrade.currency, smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, smm.objects.SMMBaseObject.id, smm.objects.Exchange.id, smm.objects.Currency.id, smm.objects.Share.id, smm.objects.DailyQuote.id, smm.objects.Transaction.id, smm.objects.Watch.id, smm.objects.Position.id, smm.objects.DailyQuote.open, smm.objects.Position.open, gui.dialogs.DlgTrade.share, gui.dialogs.DlgShare.share, smm.objects.DailyQuote.share, smm.objects.Watch.share, and smm.objects.Position.share.
Referenced by smm.objects.SMMBaseObject.__repr__().
def smm.objects.Position.buy | ( | self, | |
count, | |||
value, | |||
fee = None , |
|||
exchange = None , |
|||
date = datetime.date.today() |
|||
) |
Buy shares for the current Position.
self | The object instance itself |
count | Number of shares to trade (decimal.Decimal ) |
value | Value of a single share (decimal.Decimal ) |
fee | Transaction.fee (decimal.Decimal ) |
exchange | Exchange to trade |
date | Transaction.date (datetime.date ) |
def smm.objects.Position.Close | ( | self | ) |
Close position.
References smm.objects.DailyQuote.open, and smm.objects.Position.open.
Referenced by gui.MainWindow.OnFileExit(), smm.objects.Position.sell(), smm.objects.Position.swap(), and smm.objects.Position.worthless().
def smm.objects.Position.dividend | ( | self, | |
count, | |||
value, | |||
date = datetime.date.today() |
|||
) |
Add a dividend Transaction.
self | The object instance itself |
count | Number of shares (decimal.Decimal ) |
value | Value per single share (decimal.Decimal ) |
date | Transaction.date (datetime.date ) |
|
static |
Query Position objects.
There are three ways for querying objects:
id
returns a Position object or None
share
Querying with share
and open
returns a Position object or None
.
The last two ways returns always a storm.store.ResultSet.
id | Returns a Position specified by id . |
open | Returns all open / closed Positions |
share | Returns all Positions matched with share . |
currency | Returns all Positions matched with currency . |
def smm.objects.Position.getAvgBuy | ( | self | ) |
Calculates the average buy price.
The functions query all transactions of the current share position and calculates the weighted arithmetic mean of all "buy" and incoming swap transactions.
It returns 0 if no suitable transaction is found.
self | The object instance itself |
decimal.Decimal
valueReferences smm.objects.Position.transactions.
|
static |
|
static |
Returns all Position with Transaction between start
and end
date.
start | Start date |
end | End date |
open | Look for open Position only |
def smm.objects.Position.getLastQuote | ( | self | ) |
Returns the latest quotation of a share.
The function returns a tuple of two values:
decimal.Decimal
) datetime.Date
)All return values are None
in case of error.
The function returns the latest daily quote if found. Otherwise, is returns the data based on the last transaction. Or two times None, if nothing has been found.
Dividend transactions will be ignored.
References gui.dialogs.DlgTrade.currency, smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, gui.dialogs.DlgTrade.share, gui.dialogs.DlgShare.share, smm.objects.DailyQuote.share, smm.objects.Watch.share, smm.objects.Position.share, and smm.objects.Position.transactions.
Referenced by smm.objects.Position.getPerf(), and smm.objects.Position.getVolume().
def smm.objects.Position.getPerf | ( | self, | |
withFee = False |
|||
) |
Calculates the performance of a Position.
self | The object instance itself |
withFee | Calculate performance with or without |
decimal.Decimal
("0") for no suitable transactions.References smm.objects.Position.getLastQuote(), smm.objects.Position.getShareCount(), gui.dialogs.DlgTrade.share, gui.dialogs.DlgShare.share, smm.objects.DailyQuote.share, smm.objects.Watch.share, smm.objects.Position.share, and smm.objects.Position.transactions.
def smm.objects.Position.getShareCount | ( | self | ) |
Returns the numbers of shares in this position.
References smm.objects.Position.transactions.
Referenced by smm.objects.Position.getPerf(), smm.objects.Position.getVolume(), smm.objects.Position.sell(), smm.objects.Position.split(), smm.objects.Position.swap(), and smm.objects.Position.worthless().
|
static |
Calculate the volume of all open positions.
currency | Specifies the currency to summarise all open positions |
decimal.Decimal
)def smm.objects.Position.getVolume | ( | self | ) |
Calculate the volume of a Position.
decimal.Decimal
References smm.objects.Position.getLastQuote(), and smm.objects.Position.getShareCount().
def smm.objects.Position.Open | ( | self | ) |
Re-open position.
References smm.objects.DailyQuote.open, and smm.objects.Position.open.
Referenced by smm.objects.Position.removeTransaction().
def smm.objects.Position.removeTransaction | ( | self, | |
transaction, | |||
deleteRelated = True |
|||
) |
Delete a transaction related to this position.
The position will be reopened after a transaction has been removed.
self | The object instance itself |
transaction | The smm.objects.Transaction object |
deleteRelated | Delete related transactions too |
ValueError | Raised if transaction not part of this position |
References smm.objects.Position.Open(), and smm.objects.Position.transactions.
def smm.objects.Position.sell | ( | self, | |
count, | |||
value, | |||
fee = None , |
|||
exchange = None , |
|||
date = datetime.date.today() , |
|||
autoclose = True |
|||
) |
Sell parts of the current Position.
self | The object instance itself |
count | Number of shares to trade (decimal.Decimal ) |
value | Value of a single share (decimal.Decimal ), use Transaction.NO_VALUE for worthless expired positions |
fee | Transaction.fee (decimal.Decimal ) |
exchange | Exchange to trade |
date | Transaction.date (datetime.date ) |
autoclose | Close position if position is empty after this transaction |
References smm.objects.Position.Close(), and smm.objects.Position.getShareCount().
def smm.objects.Position.split | ( | self, | |
oratio, | |||
nratio, | |||
date = datetime.date.today() |
|||
) |
Do a share split.
Splitting means that the position will be decreased by the number of old shares and increased by the number of new shares. The whole position will be split. The split will be realised within two transactions.
self | The object instance itself |
oratio | Ratio old to new shares (decimal.Decimal ) |
nratio | Ratio old to new shares (decimal.Decimal ) |
date | Split date (datetime.date ) |
References smm.objects.Position.getShareCount(), gui.dialogs.DlgTrade.share, gui.dialogs.DlgShare.share, smm.objects.DailyQuote.share, smm.objects.Watch.share, and smm.objects.Position.share.
def smm.objects.Position.swap | ( | self, | |
oratio, | |||
nratio, | |||
ovalue, | |||
nvalue, | |||
nshare, | |||
date = datetime.date.today() , |
|||
autoclose = True |
|||
) |
Do a stock swap.
The whole position will be swapped. If an open position exists for nshare
, the new shares will be booked into.
self | The object instance itself |
oratio | Ratio old to new shares (decimal.Decimal ) |
nratio | Ratio old to new shares (decimal.Decimal ) |
date | Split date (datetime.date ) |
ovalue | Value of a single old share (decimal.Decimal ) |
nvalue | Value of a single new share (decimal.Decimal ) |
nshare | Share to swap in |
autoclose | Close position if position is empty after this transaction |
References smm.objects.Position.Close(), gui.dialogs.DlgTrade.currency, smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, and smm.objects.Position.getShareCount().
def smm.objects.Position.worthless | ( | self, | |
fee = None , |
|||
exchange = None , |
|||
date = datetime.date.today() , |
|||
autoclose = True |
|||
) |
Whole position expired worthless.
It's a sell with Transaction.NO_VALUE
self | The object instance itself |
fee | Transaction.fee (decimal.Decimal ) |
exchange | Exchange to trade |
date | Transaction.date (datetime.date ) |
autoclose | Close position if position is empty after this transaction |
References smm.objects.Position.Close(), and smm.objects.Position.getShareCount().
|
staticprivate |
Use given table to store all of this class inside.
|
static |
Referenced by smm.objects.SMMBaseObject._setAttrs().
|
static |
|
static |
ID of the referred Currency object.
|
static |
Unique ID for each object.
Referenced by smm.objects.Exchange.__str__(), smm.objects.Currency.__str__(), smm.objects.Share.__str__(), smm.objects.DailyQuote.__str__(), smm.objects.Transaction.__str__(), smm.objects.Watch.__str__(), smm.objects.Position.__str__(), smm.objects.SMMBaseObject._remove(), and smm.objects.Transaction.getVolume().
|
static |
Additional notes to this position.
|
static |
Flag to mark open positions.
Referenced by smm.objects.DailyQuote.__str__(), smm.objects.Position.__str__(), smm.objects.Position.Close(), and smm.objects.Position.Open().
|
static |
Reference to the Share object
Referenced by smm.objects.Watch.__init__(), smm.objects.DailyQuote.__str__(), smm.objects.Watch.__str__(), smm.objects.Position.__str__(), gui.dialogs.DlgTrade._prepareBuy(), gui.dialogs.DlgShare._processInput(), gui.dialogs.DlgShare._setShare(), gui.dialogs.DlgShare._validateInput(), smm.objects.Position.getLastQuote(), smm.objects.Position.getPerf(), gui.dialogs.DlgTrade.OnUpdateExistingPosition(), gui.dialogs.DlgTrade.OnUpdateNewPosition(), smm.objects.Watch.remove(), and smm.objects.Position.split().
|
static |
Property to store the ID of the referred Share object.
|
static |
Property to store the ID of the referred Stop object.
|
static |
Reference to all Transaction associated to this position
Referenced by smm.objects.Position.getAvgBuy(), smm.objects.Position.getLastQuote(), smm.objects.Position.getPerf(), smm.objects.Position.getShareCount(), and smm.objects.Position.removeTransaction().