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

Class to handle transations. More...

Inheritance diagram for smm.objects.Transaction:

Public Member Functions

def __init__ (self, count, kind, position, date=datetime.date.today(), exchange=None, fee=None, value=None, details=None)
 Create a new Transaction instance. More...
 
def __str__ (self)
 Returns the content of this instance as string. More...
 
def getVolume (self, withFee=True)
 Calculate the transaction volume. More...
 
def getHoldingPeriod (self, date=datetime.date.today())
 Returns the holding period of shares. More...
 
def getSplitDetails (self)
 Get details of a split transaction. More...
 
def getSwapDetails (self)
 Get details of a swap transaction. More...
 
def setSplitDetails (self, peer)
 Set split transaction details. More...
 
def setSwapDetails (self, peer)
 Set swap transaction details. More...
 
def remove (self)
 Delete 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)
 Query Transaction objects. More...
 
def getCount ()
 Returns the total number of Transaction. More...
 
def getInPeriod (start, end, pos=None)
 Returns all Transaction between start and end date. More...
 

Static Public Attributes

dictionary arguments
 
string psTopic = 'smm.transaction'
 
 id = Int(default=AutoReload, primary=True)
 Unique ID for each object. More...
 
 count = Decimal()
 Number of shares to buy or sell. More...
 
 value = Decimal()
 Value of one share. More...
 
 fee = Decimal()
 Overall transation fee. More...
 
 date = Date()
 Date of the transaction. More...
 
 exchange_id = Int()
 Property to store the ID of the referred Exchange object. More...
 
 exchange = Reference(exchange_id, Exchange.id)
 Reference to the Exchange object More...
 
 kind
 Type of transaction. More...
 
 position_id = Int()
 Property to store the ID of the referred Position object. More...
 
 position = Reference(position_id, 'Position.id')
 Reference to the Position object More...
 
 details = Unicode()
 Additional details for this transaction. More...
 
 NO_VALUE = decimal.Decimal('0.0000000000001')
 Very small value non-zero value to use for worthless expired positions. 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...
 

Private Member Functions

def _getDetails (self, kind)
 Get details of a transaction. More...
 
def _setDetails (self, kind, peer)
 Set transaction details. More...
 

Static Private Attributes

string __storm_table__ = "t_transaction"
 Use given table to store all of this class inside. More...
 

Detailed Description

Class to handle transations.

Test:
tests.test_objects.TestObjects.test_Transaction_objects()

Constructor & Destructor Documentation

◆ __init__()

def smm.objects.Transaction.__init__ (   self,
  count,
  kind,
  position,
  date = datetime.date.today(),
  exchange = None,
  fee = None,
  value = None,
  details = None 
)

Create a new Transaction instance.

Parameters
selfThe object instance itself
countNumber of shares to trade (decimal.Decimal)
dateTransaction.date (datetime.date)
detailsTransaction.details
exchangeExchange to trade
feeTransaction.fee (decimal.Decimal)
kindTransaction.kind
valueValue of a single share (decimal.Decimal)
positionPosition object
Exceptions
ValueErrorRaised for missing arguments

References smm.objects.Transaction.position.

Member Function Documentation

◆ __str__()

def smm.objects.Transaction.__str__ (   self)

Returns the content of this instance as string.

References smm.objects.SMMBaseObject._encode(), smm.objects.Transaction.count, smm.objects.DailyQuote.date, smm.objects.Transaction.date, smm.objects.Exchange.id, smm.objects.Currency.id, smm.objects.Share.id, smm.objects.DailyQuote.id, smm.objects.Transaction.id, smm.objects.Share.kind, smm.objects.Transaction.kind, smm.objects.Transaction.NO_VALUE, smm.objects.Transaction.position, and smm.objects.Transaction.value.

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

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

◆ _getDetails()

def smm.objects.Transaction._getDetails (   self,
  kind 
)
private

Get details of a transaction.

Parameters
selfThe object instance itself
kindtransaction kind
Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-split transactions
See also
setSplitDetails()

References smm.objects.Transaction.details, smm.objects.Share.kind, and smm.objects.Transaction.kind.

Referenced by smm.objects.Transaction.getSplitDetails(), and smm.objects.Transaction.getSwapDetails().

Here is the caller graph for this function:

◆ _setDetails()

def smm.objects.Transaction._setDetails (   self,
  kind,
  peer 
)
private

Set transaction details.

Parameters
selfThe object instance itself
kindtransaction kind
peerPeer transaction
Exceptions
ValueErrorRaised wrong transactions kind
Parameters
selfThe object instance itself
peerPeer transaction

References smm.objects.Transaction.count, smm.objects.Share.kind, smm.objects.Transaction.kind, and smm.objects.SMMBaseObject.update().

Referenced by smm.objects.Transaction.setSplitDetails(), and smm.objects.Transaction.setSwapDetails().

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

◆ get()

def smm.objects.Transaction.get (   id = None)
static

Query Transaction objects.

Parameters
idReturns a single transaction specified by id.
Sorting:
The result is ordered ascending by date
Test:
tests.test_objects.TestObjects.test_Transaction_get()

◆ getCount()

def smm.objects.Transaction.getCount ( )
static

Returns the total number of Transaction.

◆ getHoldingPeriod()

def smm.objects.Transaction.getHoldingPeriod (   self,
  date = datetime.date.today() 
)

Returns the holding period of shares.

The function calculates the difference between a transaction date and given date.

Parameters
selfThe object instance itself
dateDate of the end of the holding period
Returns
The duration in days

References smm.objects.DailyQuote.date, and smm.objects.Transaction.date.

◆ getInPeriod()

def smm.objects.Transaction.getInPeriod (   start,
  end,
  pos = None 
)
static

Returns all Transaction between start and end date.

Parameters
startStart date
endEnd date
posReturn transactions associated with this Position

◆ getSplitDetails()

def smm.objects.Transaction.getSplitDetails (   self)

Get details of a split transaction.

Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-split transactions
See also
setSplitDetails()
_getDetails()
Test:
tests.test_objects.TestObjects.test_Position_split()

References smm.objects.Transaction._getDetails().

Here is the call graph for this function:

◆ getSwapDetails()

def smm.objects.Transaction.getSwapDetails (   self)

Get details of a swap transaction.

Returns
Tuple of peer transaction, ratio old count, ratio new count Values are None in case of errors
Exceptions
ValueErrorRaised for non-swap transactions
See also
setSwapDetails()
_getDetails()
Test:
tests.test_objects.TestObjects.test_Position_swap()

References smm.objects.Transaction._getDetails().

Here is the call graph for this function:

◆ getVolume()

def smm.objects.Transaction.getVolume (   self,
  withFee = True 
)

Calculate the transaction volume.

Aquisitions increased the volume. Sales decreases it. Dividends are added to the volume. Splits and swaps don't have any effect.

Fees are processed for buy and sell transactions only.

Parameters
selfThe object instance itself
withFeeInclude the transaction fees in the volume
Returns
Volume of the transactions as decimal.Decimal value. Split transactions returns decimal.Decimal('0'). Worthless transactions returns decimal.Decimal('0').
Test:
tests.test_objects.TestObjects.test_Transaction_getVolume()

References smm.objects.Transaction.count, smm.objects.Transaction.fee, smm.objects.Exchange.id, smm.objects.Currency.id, smm.objects.Share.id, smm.objects.DailyQuote.id, smm.objects.Transaction.id, smm.objects.Share.kind, smm.objects.Transaction.kind, smm.objects.Transaction.NO_VALUE, and smm.objects.Transaction.value.

◆ remove()

def smm.objects.Transaction.remove (   self)

Delete position.

The reference between share and watch list entry will be cleaned and Watch object will be removed from the database.

Emitted Notification:
smm.position.change, smm.transaction.remove
See also
SMMBaseObject._remove()

References smm.objects.SMMBaseObject._remove(), and smm.objects.Transaction.position.

Here is the call graph for this function:

◆ setSplitDetails()

def smm.objects.Transaction.setSplitDetails (   self,
  peer 
)

Set split transaction details.

Parameters
selfThe object instance itself
peerPeer transaction
Exceptions
ValueErrorRaised for non-split transactions
See also
getSplitDetails()
_setDetails()

References smm.objects.Transaction._setDetails().

Here is the call graph for this function:

◆ setSwapDetails()

def smm.objects.Transaction.setSwapDetails (   self,
  peer 
)

Set swap transaction details.

Parameters
selfThe object instance itself
peerPeer transaction
Exceptions
ValueErrorRaised for non-swap transactions
See also
getSwapDetails()
_setDetails()

References smm.objects.Transaction._setDetails().

Here is the call graph for this function:

Member Data Documentation

◆ __storm_table__

string smm.objects.Transaction.__storm_table__ = "t_transaction"
staticprivate

Use given table to store all of this class inside.

◆ arguments

dictionary smm.objects.Transaction.arguments
static
Initial value:
= {
'count': 'decimal',
'value': 'decimal',
'fee': 'decimal',
'date': None,
'exchange': None,
'exchange_id': None,
'kind': 'unicode',
'position': None,
'position_id': None,
'details': 'unicode',
}

◆ count

smm.objects.Transaction.count = Decimal()
static

◆ date

smm.objects.Transaction.date = Date()
static

◆ details

smm.objects.Transaction.details = Unicode()
static

Additional details for this transaction.

Currently supported events:

  • split outgoing (negative count)
    split:id peer transaction:ratio old:ratio new
  • split incoming (positive count)
    split:id peer transaction:ratio old:ratio new
  • swap outgoing (negative count)
    swap:id peer transaction:ratio old:ratio new
  • swap incoming (positive count)
    swap:id peer transaction:ratio old:ratio new
  • Worthless transactions (value == Transaction.NO_VALUE)
    worthless expired

Referenced by smm.objects.Transaction._getDetails().

◆ exchange

smm.objects.Transaction.exchange = Reference(exchange_id, Exchange.id)
static

Reference to the Exchange object

◆ exchange_id

smm.objects.Transaction.exchange_id = Int()
static

Property to store the ID of the referred Exchange object.

◆ fee

smm.objects.Transaction.fee = Decimal()
static

Overall transation fee.

Referenced by smm.objects.Transaction.getVolume().

◆ id

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

◆ kind

smm.objects.Transaction.kind
static
Initial value:
= Enum(map={u'buy': 1, u'sell': 2, u'dividend': 3, u'split': 4,
u'swap': 5})

Type of transaction.

Adapt functions below after adding a new kind:

Referenced by smm.objects.Transaction.__str__(), smm.objects.Transaction._getDetails(), smm.objects.Transaction._setDetails(), and smm.objects.Transaction.getVolume().

◆ NO_VALUE

smm.objects.Transaction.NO_VALUE = decimal.Decimal('0.0000000000001')
static

Very small value non-zero value to use for worthless expired positions.

Referenced by smm.objects.Transaction.__str__(), and smm.objects.Transaction.getVolume().

◆ position

smm.objects.Transaction.position = Reference(position_id, 'Position.id')
static

◆ position_id

smm.objects.Transaction.position_id = Int()
static

Property to store the ID of the referred Position object.

◆ psTopic

string smm.objects.Transaction.psTopic = 'smm.transaction'
static

◆ value

smm.objects.Transaction.value = Decimal()
static

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