THIS CODE IS STORED IN THE SCORING RULES MODULE Public Sub ScoreSellingStock(baseScore As Integer, recommendation As Transaction, tDate As Date) Dim adjustment As Double = 0 Dim cRec As New Transaction ' this is a CANDIDATE rec, do not confuse with recommendation! cRec.symbol = recommendation.familyTicker cRec.type = "Sell" cRec.familyDelta = recommendation.familyDelta If IsInIP(cRec.symbol) Then Exit Sub ' cannot sell if in IP Else cRec.currentPositionInAP = GetCurrentPositionInAP(cRec.symbol) If cRec.currentPositionInAP <= 0 Then ' we cannot sell since we are not long Exit Sub Else cRec.delta = 1 cRec.hedgeQty = CalcQtyNeededToHedge(cRec.symbol, cRec.delta, cRec.familyDelta) If cRec.hedgeQty = 0 Then Exit Sub ' nothing to sell Else If cRec.hedgeQty > cRec.currentPositionInAP Then ' you have fewer than needed, so cRec.qty = cRec.currentPositionInAP ' sell all you have. adjustment = -50 ' Arbitrary adjustment! Else cRec.qty = cRec.hedgeQty End If cRec.score = baseScore + adjustment CandidateRecList.Add(cRec) End If End If End If End Sub Public Sub ScoreBuyingStock(baseScore As Integer, recommendation As Transaction, tDate As Date) Dim cRec As New Transaction ' this is the CANDIDATE rec, do not confuse with recommendation! cRec.symbol = recommendation.familyTicker cRec.type = "Buy" cRec.familyDelta = recommendation.familyDelta Dim adjustment As Double = 0 Dim maxBuy As Double If IsInIP(cRec.symbol) Then Exit Sub ' cannot buy if in IP End If If AvailableCashIsLow() Then Exit Sub End If cRec.currentPositionInAP = GetCurrentPositionInAP(cRec.symbol) If cRec.currentPositionInAP < 0 Then ' if short then we need a buyback Exit Sub Else cRec.delta = 1 cRec.hedgeQty = CalcQtyNeededToHedge(cRec.symbol, cRec.delta, cRec.familyDelta) maxBuy = MaxPurchasePossible(cRec.symbol, tDate) ' how many can we afford? If maxBuy < cRec.hedgeQty Then cRec.qty = maxBuy adjustment = -50 Else cRec.qty = cRec.hedgeQty End If If cRec.qty > 0 Then cRec.score = baseScore + adjustment CandidateRecList.Add(cRec) End If End If End Sub