Share and Money Management  0.16
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
 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...
 

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)

Returns the content of this instance as string.

References smm.objects.SMMBaseObject._encode(), smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, 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, smm.objects.DailyQuote.share, smm.objects.Watch.share, and smm.objects.Position.share.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

References smm.objects.Position.sell().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 an 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" transactions.

Parameters
selfThe object instance itself
Returns
Average buy as decimal.Decimal value

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 smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, 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(), 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 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.buy(), 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(), smm.objects.Position.getShareCount(), and smm.objects.Position.worthless().

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

Here is the call graph for this function:
Here is the caller 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 decreased by the number of old shares and incresed by the number of new shares. The whole position will be splitted. 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(), smm.objects.DailyQuote.share, smm.objects.Watch.share, smm.objects.Position.share, and smm.objects.Position.swap().

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 a 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(), smm.objects.Share.currency, smm.objects.DailyQuote.currency, smm.objects.Position.currency, and smm.objects.Position.getShareCount().

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

Here is the call graph for this function:
Here is the caller 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().

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

Here is the call graph for this function:
Here is the caller 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': None,
'currency': None,
'notes': 'unicode',
'open': None,
'share_id': None,
'share': None,
}

◆ 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

Unique ID for each object.

Referenced by smm.objects.Position.__str__(), and smm.objects.SMMBaseObject._remove().

◆ 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
static
Initial value:
= ReferenceSet(
id,
Transaction.position_id
)

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


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