Share and Money Management 0.18devel
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Attributes | List of all members
smm.objects.Position Class Reference

Class to handle watch list entries. More...

Inheritance diagram for smm.objects.Position:

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...
 

Detailed Description

Class to handle watch list entries.

Test:
tests.test_objects.TestObjects.test_Position_objects()

Member Function Documentation

◆ __str__()

def smm.objects.Position.__str__ (   self)

◆ buy()

def smm.objects.Position.buy (   self,
  count,
  value,
  fee = None,
  exchange = None,
  date = datetime.date.today() 
)

Buy shares for the current Position.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
valueValue of a single share (decimal.Decimal)
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add

◆ Close()

def smm.objects.Position.Close (   self)

Close position.

Emitted Notification:
smm.position.change

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().

Here is the caller graph for this function:

◆ dividend()

def smm.objects.Position.dividend (   self,
  count,
  value,
  date = datetime.date.today() 
)

Add a dividend Transaction.

Parameters
selfThe object instance itself
countNumber of shares (decimal.Decimal)
valueValue per single share (decimal.Decimal)
dateTransaction.date (datetime.date)
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add

◆ get()

def smm.objects.Position.get (   id = None,
  open = None,
  share = None,
  currency = None 
)
static

Query Position objects.

There are three ways for querying objects:

  • Querying by id returns a Position object or None
  • Querying entries using share
  • Querying without parameters to get all Position objects

Querying with share and open returns a Position object or None.

The last two ways returns always a storm.store.ResultSet.

Parameters
idReturns a Position specified by id.
openReturns all open / closed Positions
shareReturns all Positions matched with share.
currencyReturns all Positions matched with currency.
Sorting:
The result are unsorted
Test:
tests.test_objects.TestObjects.test_Position_get()

◆ getAvgBuy()

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.

Parameters
selfThe object instance itself
Returns
Average buy as decimal.Decimal value
Test:
tests.test_objects.TestObjects.test_Position_getAvgBuy()

References smm.objects.Position.transactions.

◆ getCount()

def smm.objects.Position.getCount (   closed = False,
  open = False 
)
static

Returns the number of known Positions.

Parameters
openReturns the number of all open Position objects
closedReturns the number of all closed Position objects

◆ getInPeriod()

def smm.objects.Position.getInPeriod (   start,
  end,
  open = False 
)
static

Returns all Position with Transaction between start and end date.

Parameters
startStart date
endEnd date
openLook for open Position only
Sorting:
The result are unsorted

◆ getLastQuote()

def smm.objects.Position.getLastQuote (   self)

Returns the latest quotation of a share.

The function returns a tuple of two values:

  • the quotation (type decimal.Decimal)
  • the date (type 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.

Returns
A tuple of quotation and date
Test:
tests.test_objects.TestObjects.test_Position_getLastQuote()

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().

Here is the caller graph for this function:

◆ getPerf()

def smm.objects.Position.getPerf (   self,
  withFee = False 
)

Calculates the performance of a Position.

Parameters
selfThe object instance itself
withFeeCalculate performance with or without
Returns
The absolute and relative performance in a tuple.
Two times decimal.Decimal("0") for no suitable transactions.
Test:
tests.test_objects.TestObjects.test_Position_getPerf()

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.

Here is the call graph for this function:

◆ getShareCount()

def smm.objects.Position.getShareCount (   self)

Returns the numbers of shares in this position.

Test:
tests.test_objects.TestObjects.test_Position_getPerf()

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().

Here is the caller graph for this function:

◆ getTotalVolume()

def smm.objects.Position.getTotalVolume (   currency)
static

Calculate the volume of all open positions.

Parameters
currencySpecifies the currency to summarise all open positions
Returns
Volume (decimal.Decimal)
See also
getVolume()

◆ getVolume()

def smm.objects.Position.getVolume (   self)

Calculate the volume of a Position.

Returns
Volume in decimal.Decimal
See also
getTotalVolume()

References smm.objects.Position.getLastQuote(), and smm.objects.Position.getShareCount().

Here is the call graph for this function:

◆ Open()

def smm.objects.Position.Open (   self)

Re-open position.

Emitted Notification:
smm.position.add

References smm.objects.DailyQuote.open, and smm.objects.Position.open.

Referenced by smm.objects.Position.removeTransaction().

Here is the caller graph for this function:

◆ 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.

Parameters
selfThe object instance itself
transactionThe smm.objects.Transaction object
deleteRelatedDelete related transactions too
Exceptions
ValueErrorRaised if transaction not part of this position

References smm.objects.Position.Open(), and smm.objects.Position.transactions.

Here is the call graph for this function:

◆ sell()

def smm.objects.Position.sell (   self,
  count,
  value,
  fee = None,
  exchange = None,
  date = datetime.date.today(),
  autoclose = True 
)

Sell parts of the current Position.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
valueValue of a single share (decimal.Decimal), use Transaction.NO_VALUE for worthless expired positions
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
autocloseClose position if position is empty after this transaction
Returns
The created transaction object
Emitted Notification:
smm.position.change, smm.transaction.add

References smm.objects.Position.Close(), and smm.objects.Position.getShareCount().

Here is the call graph for this function:

◆ split()

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.

Parameters
selfThe object instance itself
oratioRatio old to new shares (decimal.Decimal)
nratioRatio old to new shares (decimal.Decimal)
dateSplit date (datetime.date)
Returns
Both split transactions (outgoing and incoming)
See also
smm.Transaction.getSplitDetails()
smm.Transaction.setSplitDetails()
Emitted Notification:
smm.position.change, smm.transaction.add, smm.dailyquote.change

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.

Here is the call graph for this function:

◆ swap()

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.

Parameters
selfThe object instance itself
oratioRatio old to new shares (decimal.Decimal)
nratioRatio old to new shares (decimal.Decimal)
dateSplit date (datetime.date)
ovalueValue of a single old share (decimal.Decimal)
nvalueValue of a single new share (decimal.Decimal)
nshareShare to swap in
autocloseClose position if position is empty after this transaction
Returns
Both swap transactions (outgoing and incoming)
See also
smm.Transaction.getSwapDetails()
smm.Transaction.setSwapDetails()
Test:
tests.test_objects.TestObjects.test_Position_swap()
Emitted Notification:
smm.transaction.add, smm.position.add, smm.position.change

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().

Here is the call graph for this function:

◆ worthless()

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

Parameters
selfThe object instance itself
feeTransaction.fee (decimal.Decimal)
exchangeExchange to trade
dateTransaction.date (datetime.date)
autocloseClose position if position is empty after this transaction
Returns
The created transaction object
Test:
tests.test_objects.TestObjects.test_Position_worthless()
Emitted Notification:
smm.position.change, smm.transaction.add

References smm.objects.Position.Close(), and smm.objects.Position.getShareCount().

Here is the call graph for this function:

Member Data Documentation

◆ __storm_table__

string smm.objects.Position.__storm_table__ = "t_position"
staticprivate

Use given table to store all of this class inside.

◆ arguments

dictionary smm.objects.Position.arguments
static
Initial value:
= {
"currency_id",
"currency",
"notes",
"open",
"share_id",
"share",
}

Referenced by smm.objects.SMMBaseObject._setAttrs().

◆ currency

smm.objects.Position.currency = Reference(currency_id, Currency.id)
static

◆ currency_id

smm.objects.Position.currency_id = Int()
static

ID of the referred Currency object.

◆ id

smm.objects.Position.id = Int(default=AutoReload, primary=True)
static

◆ notes

smm.objects.Position.notes = Unicode()
static

Additional notes to this position.

◆ open

smm.objects.Position.open = Bool(default=True)
static

◆ psTopic

string smm.objects.Position.psTopic = "smm.position"
static

◆ share

smm.objects.Position.share = Reference(share_id, Share.id)
static

◆ share_id

smm.objects.Position.share_id = Int()
static

Property to store the ID of the referred Share object.

◆ stop_id

smm.objects.Position.stop_id = Int()
static

Property to store the ID of the referred Stop object.

◆ transactions

smm.objects.Position.transactions = ReferenceSet(id, Transaction.position_id)
static

The documentation for this class was generated from the following file: