longSir

流水不争先,争的是滔滔不绝

导航

模拟交易lisp代码

(defparameter *money* 200000)
(defparameter *buy* 15.39)
(defparameter *sell* 15.69)
(defparameter *value*  '(15.79 15.69 15.69 15.69 15.69 15.69 15.59 15.69 15.69))
(defparameter *hand* 4)
(defparameter *stock* 0)
(defparameter *buy-money* 0.0)
(defparameter *sell-money* 0.0)
(defparameter *buy-cost* 0.0)
(defparameter *sell-cost* 0.0)
(defparameter *total-cost* 0.0)
(defparameter *win-money* 0.0)
(defparameter *stamp-duty-rate* 0.001)
(defparameter *transfer-fee-rate* 0.00002)
(defparameter *handling-rate* 0.0000687)
(defparameter *commission-rate* 0.00025)
(defun commission-money (money)
	(let ((a (* money (+ *handling-rate* *commission-rate*))))
	(if (< a 5.0) 5.0 a)))
(defun buy-cost ()
	(+ (* *buy-money* *transfer-fee-rate*)
		(commission-money *buy-money*)))
(defun sell-cost ()
	(+ (* *sell-money* *stamp-duty-rate*)
		(* *sell-money* *transfer-fee-rate*)
		(commission-money *sell-money*)))
(defun print-info ()
	(format t "~%money buy sell stock~%")
	(format t "~A ~A ~A ~A ~%" *money* *buy* *sell* *stock*)
	(format t "bcost scost tcost wmoney~%")
	(format t "~A ~A ~A ~A ~%~%" *buy-cost* *sell-cost* *total-cost* *win-money*)
	)
(defun buy-set (b h)
	(setf *buy* b *hand* h)
	(setf *stock* (+ *stock* (* h 100)))
	(setf *buy-money* (* b h 100))
	(setf *buy-cost* (if (> h 0) (buy-cost) 0))
	(setf *total-cost* *buy-cost*)
	(setf *win-money* (- 0 *buy-money* *buy-cost*))
	(setf *money* (- *money* *buy-cost* *buy-money*))
)
(defun sell-set (s h)
	(setf *sell* s *hand* h)
	(setf *stock* (- *stock* (* h 100)))
	(setf *sell-money* (* s h 100))
	(setf *sell-cost* (if (> h 0) (sell-cost) 0))
	(setf *total-cost* *sell-cost*)
	(setf *win-money* (- *sell-money* *sell-cost*))
	(setf *money* (- *money* *sell-cost*))
	(setf *money* (+ *money* *sell-money*))
)
(defun once-set (b h s)
	(setf *buy* b *hand* h *sell* s)
	(setf *buy-money* (* b h 100) *sell-money* (* s h 100))
	(setf *buy-cost* (buy-cost) *sell-cost* (sell-cost))
	(setf *total-cost* (+ *buy-cost* *sell-cost*))
	(setf *win-money* (- *sell-money* *buy-money* *total-cost*))
	(setf *money* (+ *money* *win-money*))
	)
(defun buy (h)
	(buy-set (pop *value*) h)(print-info))
(defun sell (h)
	(sell-set (pop *value*) h)(print-info))

 

posted on 2024-02-02 10:22  tablong  阅读(9)  评论(0)    收藏  举报